Snodo.Subscription.Source behaviour (snodo v0.1.0)

Copy Markdown View Source

Application-owned event source boundary for subscriptions/listen.

Sources open a lightweight handle, pull one event at a time, and close that handle when the request is cancelled, disconnected, completed, or fails. next/2 may block; the framework always invokes it in a dedicated worker and never requests another event until the previous event has been written. open/3 must acknowledge only a subset of its requested filter. close/3 should return promptly and release any application resources associated with a blocked pull.

Summary

Types

close_reason()

@type close_reason() ::
  :cancelled | :disconnected | :complete | {:error, term()} | term()

config()

@type config() :: module() | {module(), term()} | Snodo.Subscription.Source.Config.t()

Callbacks

close(handle, close_reason, options)

@callback close(handle :: term(), close_reason(), options :: term()) :: :ok | term()

next(handle, options)

@callback next(handle :: term(), options :: term()) ::
  {:ok, Snodo.Subscription.Event.t()} | :closed | {:error, term()}

open(requested_filter, t, options)

@callback open(requested_filter :: map(), Snodo.Context.t(), options :: term()) ::
  {:ok, accepted_filter :: map(), handle :: term()}
  | {:error, Snodo.Error.t() | term()}