Looking at the GenStage Producer documentation there seems to be no built in way for the producer to be aware of which consumer is requesting demand, is this true?
handle_demand(demand, state)
I would like to create a producer that sends all messages to all consumers, thus it needs to have knowledge about the current demand received for each consumer.
According to https://hexdocs.pm/gen_stage/GenStage.html#module-producer-messages Consumer messages are sent to the Producer genserver in the following format:
{:"$gen_producer", from :: {consumer_pid, subscription_tag}, {:ask, demand}} Would it be considered bad practice to intercept such messages in order to deal with per consumer state? Any better alternatives?
#Consumer aware GenStage Producer
4 messages · Page 1 of 1 (latest)
this seems to get away from the core tenet of GenStage; that it a pull-based system, not a push-based system.
it would be very bad practice to intercept that message
did you check out the broadcast dispatcher https://hexdocs.pm/gen_stage/GenStage.BroadcastDispatcher.html ?