cfunction
src/core/os.c on line 2691, column 1
(os/pipe &opt flags)
Create a readable stream and a writable stream that are connected.
Returns a two-element tuple where the first element is a readable
stream and the second element is the writable stream. `flags` is a
keyword set of flags to disable non-blocking settings on the ends
of the pipe. This may be desired if passing the pipe to a
subprocess with `os/spawn`.
* :W - sets the writable end of the pipe to a blocking stream.
* :R - sets the readable end of the pipe to a blocking stream.
By default, both ends of the pipe are non-blocking for use with the
`ev` module.
(def [pipe-r pipe-w] (os/pipe))
(ev/spawn
# write to the pipe in a separate fiber
(for i 0 32000
(def str (string "Hello Janet " i "\n"))
(:write pipe-w str))
(:close pipe-w))
(forever
(def text (:read pipe-r 4096))
(when (nil? text) (break))
(pp text))
# read a series of strings from the pipe in parallel
# to writing to the other side, to avoid the program
# from hanging if the pipe is "full"
#
# see https://github.com/janet-lang/janet/issues/1265
(def [pipe-r pipe-w] (os/pipe))
(:write pipe-w "hello")
(:read pipe-r 5)
# => @"hello"
# send the string "hello" into the writable stream
# part and read it back from the readable one