Concord.Sync.WatchHub (Concord v2.0.0)

Copy Markdown View Source

Registry-based subscriber management for Concord's watch protocol.

Watchers register with a selector (key, prefix, or range) and receive matching events pushed to their mailbox. Supports bounded delivery queues with backpressure.

Usage

{:ok, watch_ref} = Concord.Sync.WatchHub.subscribe({:prefix, "/tasks/"}, self())

receive do
  {:concord_event, ^watch_ref, event} -> handle(event)
end

:ok = Concord.Sync.WatchHub.unsubscribe(watch_ref)

Summary

Functions

Returns a specification to start this module under a supervisor.

Returns the count of active watchers.

Delivers matching events to all registered watchers. Called by the Dispatcher.

Subscribes a process to events matching the given selector.

Unsubscribes a watch by its reference.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

count()

@spec count() :: non_neg_integer()

Returns the count of active watchers.

notify(events)

@spec notify([Concord.Sync.Event.t()]) :: :ok

Delivers matching events to all registered watchers. Called by the Dispatcher.

start_link(opts \\ [])

subscribe(selector, subscriber_pid, opts \\ [])

@spec subscribe(Concord.KV.Selector.t(), pid(), keyword()) ::
  {:ok, reference()} | {:error, term()}

Subscribes a process to events matching the given selector.

Returns {:ok, watch_ref} where watch_ref is a unique reference.

unsubscribe(watch_ref)

@spec unsubscribe(reference()) :: :ok

Unsubscribes a watch by its reference.