Fork me on GitHub
#core-async
<
2020-03-09
>
Shima09:03:20

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

fmjrey10:03:50

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?

Shima10:03:33

thanks for answering @fmjrey I have some client who wants to read from a source channel so I think I must use mult I also want the to have the most updated data so I think I must use sliding buffer for this part, but the problem is their speed aren't equals so beacuse of the synchronization in mult one client must wait for all others to done they first read ... how can I avoid this?

fmjrey10:03:00

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.

fmjrey10:03:49

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

fmjrey10:03:42

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

fmjrey10:03:02

or you may want to consider some durable queue

Shima11:03:58

thanks for your answer 🙂 @fmjrey

Shima10:03:33

thanks for answering @fmjrey I have some client who wants to read from a source channel so I think I must use mult I also want the to have the most updated data so I think I must use sliding buffer for this part, but the problem is their speed aren't equals so beacuse of the synchronization in mult one client must wait for all others to done they first read ... how can I avoid this?

zilti18:03:04

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?

zilti18:03:58

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

ghadi18:03:17

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

zilti18:03:59

I basically need it as a simple "load balancer"

ghadi18:03:18

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

ghadi18:03:50

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

ghadi18:03:10

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

zilti18:03:36

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

ghadi18:03:13

it has to be a vector though

ghadi18:03:22

so mapv, not map

zilti18:03:33

corrected 🙂

zilti18:03:06

Wow, it seems to work as expected 😄