Jido.Signal.Dispatch.Named (Jido v1.1.0-rc)

View Source

An adapter for dispatching signals to named processes in the Erlang registry.

This adapter implements the Jido.Signal.Dispatch.Adapter behaviour and provides functionality to send signals to processes registered under a name in the Erlang process registry. It supports both synchronous and asynchronous delivery modes.

Configuration Options

  • :target - (required) A tuple of {:name, atom()} specifying the registered process name
  • :delivery_mode - (optional) Either :sync or :async, defaults to :async
  • :timeout - (optional) Timeout for synchronous delivery in milliseconds, defaults to 5000
  • :message_format - (optional) Function to format the signal before sending, defaults to wrapping in {:signal, signal}

Delivery Modes

  • :async - Uses send/2 to deliver the signal without waiting for a response
  • :sync - Uses GenServer.call/3 to deliver the signal and wait for a response

Examples

# Asynchronous delivery to named process
config = {:named, [
  target: {:name, :my_process},
  delivery_mode: :async
]}

# Synchronous delivery with custom timeout
config = {:named, [
  target: {:name, :my_process},
  delivery_mode: :sync,
  timeout: 10_000
]}

# Custom message format
config = {:named, [
  target: {:name, :my_process},
  message_format: fn signal -> {:custom_signal, signal} end
]}

Error Handling

The adapter handles these error conditions:

  • :process_not_found - The named process is not registered
  • :process_not_alive - The process exists but is not alive
  • :timeout - Synchronous delivery timed out
  • Other errors from the target process

Summary

Functions

Delivers a signal to the named process.

Validates the named process adapter configuration options.

Types

delivery_error()

@type delivery_error() :: :process_not_found | :process_not_alive | :timeout | term()

delivery_mode()

@type delivery_mode() :: :sync | :async

delivery_opts()

@type delivery_opts() :: [
  target: delivery_target(),
  delivery_mode: delivery_mode(),
  timeout: timeout(),
  message_format: message_format()
]

delivery_target()

@type delivery_target() :: {:name, atom()}

message_format()

@type message_format() :: (Jido.Signal.t() -> term())

Functions

deliver(signal, opts)

@spec deliver(Jido.Signal.t(), delivery_opts()) ::
  :ok | {:ok, term()} | {:error, delivery_error()}

Delivers a signal to the named process.

Parameters

  • signal - The signal to deliver
  • opts - Validated options from validate_opts/1

Options

  • :target - (required) Tuple of {:name, atom()} identifying the process
  • :delivery_mode - (required) Either :sync or :async
  • :timeout - (optional) Timeout for sync delivery, defaults to 5000ms
  • :message_format - (optional) Function to format the signal

Returns

  • :ok - Signal delivered successfully (async mode)
  • {:ok, term()} - Signal delivered and response received (sync mode)
  • {:error, reason} - Delivery failed

validate_opts(opts)

@spec validate_opts(Keyword.t()) :: {:ok, Keyword.t()} | {:error, term()}

Validates the named process adapter configuration options.

Parameters

  • opts - Keyword list of options to validate

Options

  • :target - Must be a tuple of {:name, atom()}
  • :delivery_mode - Must be either :sync or :async

Returns

  • {:ok, validated_opts} - Options are valid
  • {:error, :invalid_target} - Target is not a valid name tuple
  • {:error, :invalid_delivery_mode} - Delivery mode is invalid