1
0
mirror of https://github.com/janet-lang/janet synced 2025-10-11 22:07:43 +00:00

Add timeout to thread/receive.

If provided, throws an error if no message is received before
timeout. Perhaps should return nil?.
This commit is contained in:
Calvin Rose
2019-12-06 09:21:36 -06:00
parent c804ae9f7c
commit 0e690b4fa0
2 changed files with 80 additions and 26 deletions

View File

@@ -57,3 +57,17 @@
(def lines (:receive (-> (thread/new) (:send worker-tree) (:send "adam") (:send 0))))
(map print lines)
#
# Receive timeout
#
(def slow (make-worker "slow-loras" 4))
(for i 0 50
(try
(let [msg (thread/receive slow 0.46)]
(print "\n" msg))
([err] (prin ".") (:flush stdout))))
(print "\ndone timing, timeouts ending.")
(try (while true (print (:receive slow))) ([err] (print "done")))