Jido.Signal.Registry (Jido Signal v1.0.0)

View Source

Registry for managing signal subscriptions.

Provides functionality to register, unregister, and manage subscriptions to signal paths with associated dispatch configurations.

Summary

Types

t()

Registry containing a unique mapping of subscription IDs to subscriptions

Functions

Returns a list of all subscriptions in the registry.

Returns the count of subscriptions in the registry.

Returns all subscriptions for a given path pattern.

Looks up a subscription by its ID.

Creates a new empty registry.

Registers a new subscription in the registry.

Unregisters a subscription from the registry.

Types

t()

@type t() :: %Jido.Signal.Registry{
  subscriptions: %{
    required(String.t()) => Jido.Signal.Registry.Subscription.t()
  }
}

Registry containing a unique mapping of subscription IDs to subscriptions

Functions

all(registry)

Returns a list of all subscriptions in the registry.

count(registry)

@spec count(t()) :: non_neg_integer()

Returns the count of subscriptions in the registry.

dbug(_, _ \\ [])

(macro)

error(_, _ \\ [])

(macro)

find_by_path(registry, path)

@spec find_by_path(t(), String.t()) :: [Jido.Signal.Registry.Subscription.t()]

Returns all subscriptions for a given path pattern.

Finds all subscriptions that would match the given signal path.

lookup(registry, id)

@spec lookup(t(), String.t()) ::
  {:ok, Jido.Signal.Registry.Subscription.t()} | {:error, :not_found}

Looks up a subscription by its ID.

Returns

  • {:ok, subscription} - Subscription was found
  • {:error, :not_found} - No subscription with this ID exists

new()

@spec new() :: t()

Creates a new empty registry.

Examples

iex> registry = Jido.Signal.Registry.new()

register(registry, id, path, dispatch)

@spec register(t(), String.t(), String.t(), term()) ::
  {:ok, t()} | {:error, :already_exists}

Registers a new subscription in the registry.

Parameters

  • registry - The current registry
  • id - Unique identifier for the subscription
  • path - Signal path pattern to subscribe to
  • dispatch - Dispatch configuration for matched signals

Returns

  • {:ok, updated_registry} - Subscription was added successfully
  • {:error, :already_exists} - A subscription with this ID already exists

Examples

iex> {:ok, registry} = Registry.register(registry, "sub1", "user.created", dispatch_config)

unregister(registry, id)

@spec unregister(t(), String.t()) :: {:ok, t()} | {:error, :not_found}

Unregisters a subscription from the registry.

Parameters

  • registry - The current registry
  • id - ID of the subscription to remove

Returns

  • {:ok, updated_registry} - Subscription was removed successfully
  • {:error, :not_found} - No subscription with this ID exists

Examples

iex> {:ok, registry} = Registry.unregister(registry, "sub1")