event v0.1.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

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

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

Link to this type 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()}}

Option values used by the init* common to :producer and :producer_consumer types

Link to this type producer_only_option()
producer_only_option() :: {:demand, :forward | :accumulate}

Option values used by the init* specific to :producer type

Option values used by the init* functions when stage type is :producer

Link to this section Functions

Link to this function async_notify(source, event)

Asynchronously notify the source that an event has occurred. Returns immediately.

Link to this function call(source, call, timeout \\ 5000)

Send a message to the event source and await a response.

Link to this function cast(source, cast)

Send an asynchronous message to the event source

Link to this function code_change(old_version, state, extra)

Handle a code change

Link to this function dispatch_events(state, events)

Dispatch as many events as possible until demand reaches zero or we run out of buffered events

Link to this function handle_call(call, from, state)

Handle a synchronous event notification

Link to this function handle_cast(call, state)

Handle an asynchronous event notification

Link to this function handle_demand(new_demand, state)

Handle demand for new events

Link to this function handle_info(info, state)

Handle an incoming message

Link to this function handle_subscribe(subscriber, opts, from, state)

Handle a subscription

Initialize event source state

Link to this function maybe_dispatch(arg, state)

Conditionally enqueue and dispatch the given event based on options such as the max allowed number of queued items

Link to this function maybe_enqueue(event, state)

Enqueue the given event if the event queue’s length is less than the configured maximum

Link to this function queue(source, timeout \\ 5000)

Get the event queue for the given source

Link to this function start_link(module, args, opts)

Start an EventSource process.

Link to this function 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

Link to this function terminate(reason, map)

Handle process termination

Link to this section Callbacks

Link to this callback code_change(old_vsn, state, extra) (optional)
code_change(old_vsn, state :: term(), extra :: term()) ::
  {:ok, new_state :: term()} | {:error, reason :: term()}
when old_vsn: term() | {:down, term()}
Link to this callback 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()
Link to this callback handle_cast(request, state) (optional)
handle_cast(request :: term(), state :: term()) ::
  {:noreply, new_state}
  | {:noreply, [event], new_state}
  | {:noreply, [event], new_state, :hibernate}
  | {:stop, reason :: term(), new_state}
when new_state: term(), event: term()
Link to this callback handle_info(message, state) (optional)
handle_info(message :: term(), state :: term()) ::
  {:noreply, new_state}
  | {:noreply, [event], new_state}
  | {:noreply, [event], new_state, :hibernate}
  | {:stop, reason :: term(), new_state}
when new_state: term(), event: term()
Link to this callback init(args)
init(args :: term()) ::
  {:ok, state}
  | {:ok, state, [producer_option()]}
  | :ignore
  | {:stop, reason :: any()}
when state: any()
Link to this callback terminate(reason, state) (optional)
terminate(reason, state :: term()) :: term()
when reason: :normal | :shutdown | {:shutdown, term()} | term()