Decree.Store.PubSub (decree v0.1.0)

Copy Markdown View Source

Pub/sub using Elixir's local Registry module.

Summary

Functions

Broadcasts message on given topic.

Return the child spec.

Subscribes the caller to the given topic.

Functions

broadcast(event_store, topic, message)

@spec broadcast(Decree.Store.t(), binary(), term()) :: :ok

Broadcasts message on given topic.

child_spec(event_store)

@spec child_spec(Decree.Store.t()) :: [:supervisor.child_spec()]

Return the child spec.

subscribe(event_store, topic, opts \\ [])

@spec subscribe(Decree.Store.t(), binary(),
  selector: (Decree.Store.RecordedEvent.t() -> any()),
  mapper: (Decree.Store.RecordedEvent.t() -> any()),
  notices: boolean()
) :: :ok | {:error, term()}

Subscribes the caller to the given topic.

notices: true also sends the caller {:events_pending, event_number} when the publisher stops a batch before an event whose type this instance does not know. A subscription process registers with it; an aggregate or a transient subscriber does not.

The publisher cuts each notification's batch on its own: an event appended after the unknown one, in a later append, is still broadcast. A subscriber without notices checks stream_version or event_number continuity itself.