Fork me on GitHub
#beginners
<
2019-11-17
>
sysarcher15:11:27

Is there a way to trigger an end to an infinite go-loop in Clojurescript? I'm looking at this example but I want to be able to stop the loop too. Right now, I'm thinking I can do this via a "global" atom (or channel) but is this the best way?: https://clojuredocs.org/clojure.core.async/go-loop#example-542c8833e4b05f4d257a297a I'm interacting with an API that provides data via a REST endpoint and I need to frequently update my frontend.

Keith15:11:18

I believe a common pattern is to pass in a channel that you use to signal a shutdown with alts

sysarcher15:11:26

Thanks Keith.. yes, I wanted to get to know the canonical way to manage this... Channels it is!

Jan K15:11:06

You can make the go-loop terminate when the input channel closes, or have a separate "exit" channel

sysarcher15:11:22

I was also thinking along the same lines. I was wondering whether this is the way actual Cljs programmers would approach the problem. Thanks for your answer!!