Skip to content

Instantly share code, notes, and snippets.

@sharpobject
Last active February 15, 2020 10:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sharpobject/362798d4dfa6d7ca4a04bf792a308146 to your computer and use it in GitHub Desktop.
Save sharpobject/362798d4dfa6d7ca4a04bf792a308146 to your computer and use it in GitHub Desktop.
Janet 1.7.0-f7ee8bd Copyright (C) 2017-2019 Calvin Rose
janet:1:> (defn my_fn [] (for i 0 10 (yield i)))
<function my_fn>
janet:2:> (defn coroutine-clone [co] (unmarshal (marshal co make-image-dict) load-image-dict))
<function coroutine-clone>
janet:3:> (def a (coro (my_fn)))
<fiber 0x00580A80>
janet:4:> (resume a)
0
janet:5:> (resume a)
1
janet:6:> (def b (coroutine-clone a))
<fiber 0x00582B58>
janet:7:> (resume a)
2
janet:8:> (resume a)
3
janet:9:> (resume b)
2
janet:10:> (resume b)
3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment