I noticed an example from the Concurrent Data Processing in Elixir book with a custom Broadway producer that works in a way as push-based event processing (at least that’s the impression I got from when I tried testing the approach). Previously when I tried implementing something similar I had problems with the consumers stopping after the first few requests (my impression is this was relative to the concurrency settings, but I might be wrong).
In the example in the book this does not happen and I noticed the handle_demand/2
callback there always returns an empty events list and the same state it receives without any changes. I wanted to ask - why does it make sense to always return an empty events list in this case, instead of returning some events? Is it there just because the consumers demand events and the producer has to return something? The pushing of events in the example works by getting the first producer process from Broadway.producer_names()
and casting the event to it. Is the handle_demand/2
with an empty events list related to this casting in any way or, if what I think is correct, it is not really related and is just to handle demand from consumers?