1
0
mirror of https://github.com/janet-lang/janet synced 2025-10-14 07:17:40 +00:00

Allow iterating over fibers with each and similar.

This commit is contained in:
Calvin Rose
2021-01-03 16:17:36 -06:00
parent ecc6eb7497
commit c357af02c2
9 changed files with 146 additions and 7 deletions

View File

@@ -0,0 +1,28 @@
(def f
(coro
(for i 0 10
(yield (string "yield " i))
(os/sleep 0))))
(print "simple yielding")
(each item f (print "got: " item ", now " (fiber/status f)))
(def f
(coro
(for i 0 10
(yield (string "yield " i))
(ev/sleep 0))))
(print "old style fiber iteration")
(eachy item f (print "got: " item ", now " (fiber/status f)))
(def f
(coro
(for i 0 10
(yield (string "yield " i))
(ev/sleep 0))))
(print "complex yielding")
(each item f (print "got: " item ", now " (fiber/status f)))
(print (fiber/status f))