core-async

2020-03-09T09:15:20.245600Z

Hi everyone I have a (probably very simple) question How can I use mult asynchronize?

fmjrey 2020-03-09T10:28:50.247Z

Hi @tajoddin.shima not sure I understand your question, some example illustrating your issue would help. Maybe keep mind this tip: https://clojuredocs.org/clojure.core.async/mult#example-563432f8e4b0290a56055d17?

fmjrey 2020-03-09T10:52:00.247600Z

I'm not sure how you can avoid this situation entirely unless you tap into the source before core.async. The doc also says so: > Use buffering/windowing to prevent slow taps from holding up the mult.

fmjrey 2020-03-09T10:55:49.247800Z

And even if you post to two different channel, you would need to decide what the source should do when one blocks.

fmjrey 2020-03-09T10:56:42.248Z

so overall you need to review the constraints you can afford in terms of lost data and or blocked thread

fmjrey 2020-03-09T10:59:02.248200Z

or you may want to consider some durable queue

2020-03-09T11:28:58.248800Z

thanks for your answer 🙂 @fmjrey

zilti 2020-03-09T18:01:04.250300Z

Am I right in assuming that an alts! where all entries are [channel-to-put-to val-to-put] , all val-to-put being identical, it will choose the channel-to-put-to that becomes available first?

zilti 2020-03-09T18:04:58.251Z

Hmm nevermind, I can't do what I want with that anyway... I'd need a variable amount of such vectors.

ghadi 2020-03-09T18:07:17.251500Z

it is correct that alts will proceed with the first available operation @zilti

zilti 2020-03-09T18:07:59.252400Z

I basically need it as a simple "load balancer"

ghadi 2020-03-09T18:08:18.252800Z

alts can take a dynamic set of channel ops as an argument

zilti 2020-03-09T18:08:38.253400Z

Ah nice

ghadi 2020-03-09T18:08:50.253600Z

(unlike alt, which is a macro, or select in go)

ghadi 2020-03-09T18:09:10.254200Z

see the core async code itself for examples of alts with dynamic args

zilti 2020-03-09T18:09:36.254400Z

What I have now is (async/alts! (map (fn [browser] [browser payload]) @browserpool*))

ghadi 2020-03-09T18:10:13.254600Z

it has to be a vector though

ghadi 2020-03-09T18:10:22.254800Z

so mapv, not map

zilti 2020-03-09T18:10:33.255Z

corrected 🙂

zilti 2020-03-09T18:30:06.255300Z

Wow, it seems to work as expected 😄