JanetDocsPlaygroundI'm feeling luckyGitHub sign in



    (ev/thread fiber &opt value flags)

    Resume a (copy of a) `fiber` in a new operating system thread, 
    optionally passing `value` to resume with. Unlike `ev/go`, this 
    function will suspend the current fiber until the thread is 
    complete. The the final result.

1 exampleSign in to add an example
# channels that can be used for communication between os threads
(def chan-a (ev/thread-chan 10))
(def chan-b (ev/thread-chan 10))

# one thread
    (fn []
      (def msg "hi")
      (print "thread 1 sending: " msg)
      (ev/give chan-a msg)
      (print "thread 1 received: " (ev/take chan-b))))

# another thread
    (fn []
      (print "thread 2 received: " (ev/take chan-a))
      (def msg "peace")
      (print "thread 2 sending: " msg)
      (ev/give chan-b msg)))

# expected output
# thread 1 sending: hi
# thread 2 received: hi
# thread 2 sending: peace
# thread 1 received: peace