Skip to content

Behavior of loop (and friends) with a fiber #1439

Answered by ianthehenry
afranchuk asked this question in Q&A
Discussion options

You must be logged in to vote

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)))
# returns-va…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@afranchuk
Comment options

@ianthehenry
Comment options

@afranchuk
Comment options

Answer selected by afranchuk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants