Right! The proposal mentions that go-blocks must check for a closed
channel at every step in order to exit early. So I'll revise the
title—core.async cannot stop *arbitrary* go-blocks.
For example, with this staggered animation code, it's not immediately clear
to me how to exit after any step. In JS, it pulls the plug for free.
(go
(dotimes [_ 3]
(swap! game assoc :board cleared)
(<! (timeout 170))
(swap! game assoc :board board)
(<! (timeout 170)))
(swap! game assoc :board cleared)
(<! (timeout 220))
(swap! game assoc :board collapsed))
Anyone coming from the Unity game engine will recognize this feature as the
StopCoroutine function. Core.async does not have such a feature. the
ergonomics matter!
On Friday, May 25, 2018 at 3:28:49 AM UTC-5, Thomas Heller wrote:
>
>
>> 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.