elixir-lang / gen_stage

Producer and consumer actors with back-pressure for Elixir
http://hexdocs.pm/gen_stage
1.48k stars 192 forks source link

Document Subscription Demand in `BroadcastDispatcher` #303

Closed maennchen closed 9 months ago

maennchen commented 9 months ago

Follow up to dicussion via Slack with @josevalim

I'm not sure if that explanation is good. I think it could be more concise.

josevalim commented 9 months ago

I think this still has a race, it is just less likely. Instead, you most likely want to do this on init:

{:producer, state, demand: :accumulate}

And then once all process subscribe, you call GenStage.demand(producer, :forward). :)

maennchen commented 9 months ago

@josevalim I've updated to the new solution. This is also way more elegant than subscribing asynchronously.

In my use case, I now have a little job that runs at the end of the containing Supervisors children, which calls all producing stages to change the demand.

josevalim commented 9 months ago

:green_heart: :blue_heart: :purple_heart: :yellow_heart: :heart: