Yes, core.async is not great for this but it was also not meant for this. 
The big abstraction there are channels or CSP. There are "zero" channels 
involved in your example so you could probably find a better abstraction to 
fit here.

There are several different concurrency models and all of them have 
drawbacks. As I said before I'm for adding support for async/await and 
generators but core.async should not even be part of the argument IMHO. I'm 
not trying to convince anyone that core.async is the best solution ever. I 
remember vividly how desperately I wanted a proper Actor-like concurrency 
primitive when I came over from Erlang. I actually only understood the 
drawbacks of Actors after I learned about CSP.

I made this example a while ago showing what Closure does when rewriting 
async/await to ES3.
https://gist.github.com/thheller/82ca9ef8a04b58aafa4624edbac383ac

We could emit that JS code directly using a few macros. The only reason 
emitting the ES6+ code makes sense is due to tool support and maybe having 
slightly more compact code, which is probably not a factor after :advanced 
is done with it. We can already interop with all of it very easily, just 
writing equivalent code is not ideal.

To be honest just adding support for async/await and generators alone 
doesn't make much sense to me. At that point we should probably look into 
emitting ES6+ESM directly instead and make proper use of all the features 
that has. Given that Closure support for ES6 is getting much better that 
might make sense at some point.


On Friday, May 25, 2018 at 4:45:22 PM UTC+2, Shaun LeBron wrote:
>
> 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 clojurescript+unsubscr...@googlegroups.com.
To post to this group, send email to clojurescript@googlegroups.com.
Visit this group at https://groups.google.com/group/clojurescript.

Reply via email to