The Starter stage

We've finally reached the first stage of this upload pipeline walk-through. As an event producer, our Starter stage will implement the handle_demand/2 callback instead of the handle_events/3 we've implemented so far for our Consumer and ProducerConsumer stages. This will also be the only stage that will keep state. As a Producer stage, the Starter stage needs to know at all times the queue from which it fetches new upload tasks and the outstanding demand it received and it has not yet fulfilled. Accordingly, its init/1 callback will return a {:producer, state} tuple where the state contains the queue, the type of events this Starter stage will create, and the pending demand.

The call to QueueWorker.queue_name/1 with :upload ...

Get Mastering Elixir now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.