Jido.Signal.Dispatch.Named (Jido Signal v1.0.0)
View SourceAn 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
- Usessend/2
to deliver the signal without waiting for a response:sync
- UsesGenServer.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
@type delivery_error() :: :process_not_found | :process_not_alive | :timeout | term()
@type delivery_mode() :: :sync | :async
@type delivery_opts() :: [ target: delivery_target(), delivery_mode: delivery_mode(), timeout: timeout(), message_format: message_format() ]
@type delivery_target() :: {:name, atom()}
@type message_format() :: (Jido.Signal.t() -> term())
Functions
@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 deliveropts
- Validated options fromvalidate_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
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