flowex v0.3.0 Flowex.Stage
Summary
Functions
Invoked on :producer_consumer and :consumer stages to handle events
Invoked when the server is started
Functions
Invoked on :producer_consumer and :consumer stages to handle events.
Must always be explicitly implemented by such types.
Return values are the same as c:handle_cast/2
.
Callback implementation for GenStage.handle_events/3
.
Invoked when the server is started.
start_link/3
(or start/3
) will block until it returns. args
is the argument term (second argument) passed to start_link/3
.
In case of successful start, this callback must return a tuple
where the first element is the stage type, which is either
a :producer
, :consumer
or :producer_consumer
if it is
taking both roles.
For example:
def init(args) do
{:producer, some_state}
end
The returned tuple may also contain 3 or 4 elements. The third
element may be the :hibernate
atom or a set of options defined
below.
Returning :ignore
will cause start_link/3
to return :ignore
and the process will exit normally without entering the loop or
calling terminate/2
.
Returning {:stop, reason}
will cause start_link/3
to return
{:error, reason}
and the process to exit with reason reason
without entering the loop or calling terminate/2
.
Options
This callback may return options. Some options are specific to the stage type while others are shared across all types.
:producer options
:demand
- when:forward
, the demand is always forwarded to thehandle_demand
callback. When:accumulate
, demand is accumulated until its mode is set to:forward
viademand/2
. This is useful as a synchronization mechanism, where the demand is accumulated until all consumers are subscribed. Defaults to:forward
.
:producer and :producer_consumer options
:buffer_size
- the size of the buffer to store events without demand. Check the “Buffer events” section on the module documentation (defaults to 10000 for:producer
,:infinity
for:producer_consumer
):buffer_keep
- returns if the:first
or:last
(default) entries should be kept on the buffer in case we exceed the buffer size:dispatcher
- the dispatcher responsible for handling demands. Defaults toGenStage.DemandDispatch
. May be either an atom or a tuple with the dispatcher and the dispatcher options
:consumer and :producer_consumer options
:subscribe_to
- a list of producers to subscribe to. Each element represents the producer or a tuple with the producer and the subscription options (as defined insync_subscribe/2
)
Dispatcher
When using a :producer
or :producer_consumer
, the dispatcher
may be configured on init as follows:
{:producer, state, dispatcher: GenStage.BroadcastDispatcher}
Some dispatchers may require options to be given on initialization, those can be done with a tuple:
{:producer, state, dispatcher: {GenStage.PartitionDispatcher, partitions: 0..3}}
Callback implementation for GenStage.init/1
.