JanetDocsPlaygroundI'm feeling luckyGitHub sign in

ev/thread-chan



    cfunction
    src/core/ev.c on line 1102, column 1

    (ev/thread-chan &opt limit)

    Create a threaded channel. A threaded channel is a channel that can 
    be shared between threads and used to communicate between any 
    number of operating system threads.


1 exampleSign in to add an example
Loading...
(def conn-chan (ev/thread-chan 1000))

(defn producer [no]
  (forever
    (ev/sleep 5)
    (print "Adding data from producer num:" no)
    (ev/give conn-chan (math/random))))

(defn consumer [no]
  (forever
    (ev/sleep 0.5)
    (def num (ev/take conn-chan))
    (print num ": Printing from consumer:" no)))

(defn main [& args]
  (ev/spawn-thread (producer 1))
  (ev/spawn-thread (consumer 1))
  (ev/spawn-thread (consumer 2))
  (ev/sleep 20)
  (print "exiting"))
Geo-7Playground