Skip to content

Instantly share code, notes, and snippets.

@telent
Created March 5, 2024 19:21
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 telent/b6616c3e166234cf0261dcd52652913e to your computer and use it in GitHub Desktop.
Save telent/b6616c3e166234cf0261dcd52652913e to your computer and use it in GitHub Desktop.
(fn sleep [x] (: (io.popen (.. "sleep " (tostring x))) :close)) ;; simulate a slow process
(fn tick-producer []
(coroutine.wrap
(fn []
(var i 0)
(while (< i 10)
(set i (+ 1 i))
(coroutine.yield i)
(sleep 1)
))))
(let [ticks (tick-producer)]
(accumulate [finished false
t ticks
&until finished]
(do (print t)
(= t 4)))
(print "next" (ticks)))
$ fennel foo.fnl
1
2
3
4
[... pauses ...]
next 6
@telent
Copy link
Author

telent commented Mar 5, 2024

;; this works, though, so I could just not use accumulate

(let [ticks (tick-producer)]
  (each [t ticks
         &until (matches? t)]
    (print t)))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment