event v0.2.0 Event.Source behaviour
Queues events for dissemination to subscribed processors and sinks. Buffers demand for events so that when the queue is refilled, connected processors and sinks receive them. Exposes various options for limiting buffering, as well as GenStage control options.
Link to this section Summary
Types
Option values used by the init*
common to :producer
and :producer_consumer
types
Option values used by the init*
specific to :producer
type
Option values used by the init*
functions when stage type is :producer
Functions
Asynchronously notify the source that an event has occurred. Returns immediately.
Send a message to the event source and await a response.
Send an asynchronous message to the event source
Handle a code change
Dispatch as many events as possible until demand reaches zero or we run out of buffered events
Handle a synchronous event notification
Handle an asynchronous event notification
Handle demand for new events
Handle an incoming message
Handle a subscription
Initialize event source state
Conditionally enqueue and dispatch the given event based on options such as the max allowed number of queued items
Enqueue the given event if the event queue's length is less than the configured maximum
Get the event queue for the given source
Start an EventSource process.
Synchronously notify the source that an event has occurred. This call will block until the event has been consumed, or until the timeout is reached
Handle process termination
Link to this section Types
producer_and_producer_consumer_option()
producer_and_producer_consumer_option() ::
{:buffer_size, non_neg_integer() | :infinity}
| {:buffer_keep, :first | :last}
| {:dispatcher, module() | {module(), GenStage.Dispatcher.options()}}
producer_and_producer_consumer_option() :: {:buffer_size, non_neg_integer() | :infinity} | {:buffer_keep, :first | :last} | {:dispatcher, module() | {module(), GenStage.Dispatcher.options()}}
Option values used by the init*
common to :producer
and :producer_consumer
types
producer_only_option()
producer_only_option() :: {:demand, :forward | :accumulate}
producer_only_option() :: {:demand, :forward | :accumulate}
Option values used by the init*
specific to :producer
type
producer_option()
producer_option() ::
producer_only_option() | producer_and_producer_consumer_option()
producer_option() :: producer_only_option() | producer_and_producer_consumer_option()
Option values used by the init*
functions when stage type is :producer
Link to this section Functions
async_notify(source, event)
Asynchronously notify the source that an event has occurred. Returns immediately.
call(source, call, timeout \\ 5000)
Send a message to the event source and await a response.
cast(source, cast)
Send an asynchronous message to the event source
code_change(old_version, state, extra)
Handle a code change
dispatch_events(state, events)
Dispatch as many events as possible until demand reaches zero or we run out of buffered events
handle_call(call, from, state)
Handle a synchronous event notification
handle_cast(call, state)
Handle an asynchronous event notification
handle_demand(new_demand, state)
Handle demand for new events
handle_info(info, state)
Handle an incoming message
handle_subscribe(subscriber, opts, from, state)
Handle a subscription
init(opts)
Initialize event source state
maybe_dispatch(arg, state)
Conditionally enqueue and dispatch the given event based on options such as the max allowed number of queued items
maybe_enqueue(event, state)
Enqueue the given event if the event queue's length is less than the configured maximum
queue(source, timeout \\ 5000)
Get the event queue for the given source
start_link(module, args, opts)
Start an EventSource process.
sync_notify(source, event, timeout \\ 5000)
Synchronously notify the source that an event has occurred. This call will block until the event has been consumed, or until the timeout is reached
terminate(reason, arg2)
Handle process termination
Link to this section Callbacks
code_change(old_vsn, state, extra) (optional)
handle_call(request, from, state)
(optional)
handle_call(request :: term(), from :: GenServer.from(), state :: term()) ::
{:reply, reply, new_state}
| {:reply, reply, [event], new_state}
| {:reply, reply, [event], new_state, :hibernate}
| {:noreply, new_state}
| {:noreply, [event], new_state}
| {:noreply, [event], new_state, :hibernate}
| {:stop, reason, reply, new_state}
| {:stop, reason, new_state}
when reply: term(), new_state: term(), reason: term(), event: term()
handle_call(request :: term(), from :: GenServer.from(), state :: term()) :: {:reply, reply, new_state} | {:reply, reply, [event], new_state} | {:reply, reply, [event], new_state, :hibernate} | {:noreply, new_state} | {:noreply, [event], new_state} | {:noreply, [event], new_state, :hibernate} | {:stop, reason, reply, new_state} | {:stop, reason, new_state} when reply: term(), new_state: term(), reason: term(), event: term()
handle_cast(request, state) (optional)
handle_info(message, state) (optional)
init(args)
init(args :: term()) ::
{:ok, state}
| {:ok, state, [producer_option()]}
| :ignore
| {:stop, reason :: any()}
when state: any()
init(args :: term()) :: {:ok, state} | {:ok, state, [producer_option()]} | :ignore | {:stop, reason :: any()} when state: any()