Behavior of loop
(and friends) with a fiber
#1439
-
Hi all! I'm somewhat new to Janet. However I was surprised by some behavior I observed. I have a codebase where some However, I wanted to wrap each I started with (def fiber (fiber/new f :iy))
(var yielded false)
(loop [v :in fiber]
(set yielded true)
(yield v)) but I found that this didn't work! For some reason, the loop was never executed (not even for the returned value from (while (fiber/can-resume? fiber)
(def v (resume fiber))
(set yielded true)
(yield v)) and this worked! So my question here is, what is the actual behavior of |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Consider this: (defn returns-value [] "returned this value")
(defn yields-and-returns-value [] (yield "yielded this value") "returned that value")
(print "# returns-value loop:")
(def fiber (fiber/new returns-value :iy))
(loop [v :in fiber]
(print v))
(print "\n# yields-and-returns-value loop:")
(def fiber (fiber/new yields-and-returns-value :iy))
(loop [v :in fiber]
(print v))
(print "\n# returns-value resume:")
(def fiber (fiber/new returns-value :iy))
(while (fiber/can-resume? fiber)
(print (resume fiber)))
(print "\n# yields-and-returns-value resume:")
(def fiber (fiber/new yields-and-returns-value :iy))
(while (fiber/can-resume? fiber)
(print (resume fiber)))
|
Beta Was this translation helpful? Give feedback.
Consider this: