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

Add example of stopping with events in c:handle_demand/2 #281

Closed whatyouhide closed 2 years ago

josevalim commented 2 years ago

This is the way to go but I think more work is necessary. For example, what happens if you receive a handle_demand or a handle_call after this? So we would need to block and do nothing until all events are dispatched, or give up on this idea (and let users implement it pretty much as you did it here).

whatyouhide commented 2 years ago

@josevalim you know, after thinking a bit more about this, I think you're right. The best approach for now seems to just document this with an example. I don't know that this is such a common case and the solution in the example works well enough (we're using it in production at Community, for example 😄). Reworked the PR to only be about docs, thoughts?