July 2021
Intermediate to advanced
176 pages
4h 14m
English
There is one important component of GenStage we haven’t talked about yet, and this component is the dispatcher. When :producer and :producer_consumer stages send events to consumers, it’s in fact the dispatcher that takes care of sending the events. So far we have used the default DemandDispatcher, but GenStage comes with two more. Let’s see what they do and how we can use them.
You can specify what dispatcher to use when initializing the process, using the :dispatcher key. The default is DemandDispatcher, which is equivalent to this configuration:
| | def init(state) do |
| | {:producer, state, dispatcher: GenStage.DemandDispatcher} |
| | end |
DemandDispatcher sends events to consumers with the highest demand first. ...
Read now
Unlock full access