JanetDocsPlaygroundI'm feeling luckyGitHub sign in

os/pipe



    cfunction
    src/core/os.c on line 2195, column 1

    (os/pipe)

    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.


2 examplesSign in to add an example
Loading...
(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
YohananDiamondPlayground
(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
YohananDiamondPlayground