Jido.Signal.Dispatch.PidAdapter (Jido v1.1.0-rc.2)
View SourceAn adapter for dispatching signals directly to Erlang processes using PIDs.
This adapter implements the Jido.Signal.Dispatch.Adapter
behaviour and provides
functionality to send signals to specific processes either synchronously or
asynchronously.
Configuration Options
:target
- (required) The PID of the destination process: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
config = {:pid, [
target: destination_pid,
delivery_mode: :async
]}
# Synchronous delivery with custom timeout
config = {:pid, [
target: destination_pid,
delivery_mode: :sync,
timeout: 10_000
]}
# Custom message format
config = {:pid, [
target: destination_pid,
message_format: fn signal -> {:custom_signal, signal} end
]}
Error Handling
The adapter handles various error conditions:
:process_not_alive
- The target process is not alive:timeout
- Synchronous delivery timed out- Other errors from the target process
Summary
Types
@type delivery_error() :: :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() :: pid()
@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 target process.
Parameters
signal
- The signal to deliveropts
- Validated options fromvalidate_opts/1
Options
:target
- (required) Target PID to deliver to: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 PID adapter configuration options.
Parameters
opts
- Keyword list of options to validate
Options
:target
- Must be a valid PID:delivery_mode
- Must be either:sync
or:async
Returns
{:ok, validated_opts}
- Options are valid{:error, :invalid_target}
- Target is not a valid PID{:error, :invalid_delivery_mode}
- Delivery mode is invalid