>
>
> not quite! core.async doesn't allow you to cancel a go-block (to my
> knowledge), which JS allows. I added a section on this:
>
>
> https://beta.observablehq.com/@shaunlebron/proposal-generators-and-async-functions-in-clojurescript#coreasync
>
>
This is incorrect. Closing a channel can be used to "end" a loop. In
addition it is possible to use alt! or alts! with an additional "control"
channel (or more) and "selecting" which channel to work on.
(defn foo []
(let [ch (async/chan)]
(go (loop [i 100]
(when (pos? i)
(<! (async/timeout 1000))
(when (>! ch i)
(recur (dec i)))))
(prn :loop-terminated))
ch))
(go (let [ch (foo)]
(prn (<! ch))
(prn (<! ch))
(async/close! ch)
(prn (<! ch))))
In addition the "loop" is dependent on the "ch" reference. If that gets
garbage collected the loop will be as well, similar to generators or
async/await.
--
Note that posts from new members are moderated - please be patient with your
first post.
---
You received this message because you are subscribed to the Google Groups
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/clojurescript.