ASM.Extensions.PubSub.Broadcaster (ASM v0.9.2)

Copy Markdown View Source

Async broadcaster process that publishes %ASM.Event{} outside run-critical paths.

Design notes:

  • enqueue path uses GenServer.cast/2 and never blocks callers
  • dispatch runs in monitored async tasks
  • bounded queue with drop policy protects against unbounded mailbox growth

Summary

Types

adapter_spec()

@type adapter_spec() :: {module(), keyword()}

overflow_policy()

@type overflow_policy() :: :drop_oldest | :drop_newest

state()

@type state() :: %ASM.Extensions.PubSub.Broadcaster{
  adapter_mod: module(),
  adapter_state: ASM.Extensions.PubSub.Adapter.state(),
  inflight_pid: pid() | nil,
  inflight_ref: reference() | nil,
  max_queue_size: pos_integer(),
  notify: pid() | nil,
  overflow: overflow_policy(),
  payload_builder: (ASM.Event.t(), keyword() ->
                      ASM.Extensions.PubSub.Payload.t()),
  queue: :queue.queue(),
  queue_len: non_neg_integer(),
  task_supervisor: pid(),
  topic_prefix: String.t(),
  topic_scopes: [ASM.Extensions.PubSub.Topic.scope()],
  waiters: [GenServer.from()]
}

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

enqueue(broadcaster, event, publish_opts \\ [])

@spec enqueue(pid(), ASM.Event.t(), keyword()) :: :ok

flush(broadcaster, timeout \\ 5000)

@spec flush(pid(), timeout()) :: :ok | {:error, ASM.Error.t()}

start_link(opts)

@spec start_link(keyword()) :: GenServer.on_start() | {:error, ASM.Error.t()}