Jido.Sensor.Runtime (Jido v2.0.0-rc.1)
View SourceGenServer runtime for Jido sensors.
Runtime wraps sensor modules and manages their lifecycle, similar to how AgentServer wraps agent modules. It handles configuration validation, event scheduling, and signal delivery.
Architecture
- Single GenServer per sensor instance
- Configuration validated via sensor module's
schema()(Zoi.parse) - Timer-based event scheduling via
{:schedule, interval_ms}directives - Signal delivery to agent via pid or
Jido.Signal.Dispatch
Public API
start_link/1- Start linked to callerchild_spec/1- Returns a proper child spec with stable idevent/2- Inject an external event into the sensor
Options
:sensor- Sensor module (required):config- Configuration map or keyword list for the sensor:context- Context map including:agent_ref:id- Instance ID (auto-generated if not provided)
Signal Delivery
When the sensor emits a signal:
- If
agent_refis a pid, usessend(agent_ref, {:signal, signal})(for testing) - Otherwise uses
Jido.Signal.Dispatch.dispatch/2with target: agent_ref
Examples
{:ok, pid} = Jido.Sensor.Runtime.start_link(
sensor: MySensor,
config: %{interval: 1000},
context: %{agent_ref: self()}
)
# Inject an external event
Jido.Sensor.Runtime.event(pid, :custom_event)
Summary
Functions
Returns a child_spec for supervision.
Injects an external event into the sensor.
Starts a Sensor.Runtime linked to the calling process.
Types
Functions
@spec child_spec(keyword() | map()) :: Supervisor.child_spec()
Returns a child_spec for supervision.
Uses the :id option if provided, otherwise defaults to the module name.
Injects an external event into the sensor.
The event will be passed to the sensor's handle_event/2 callback.
Examples
:ok = Jido.Sensor.Runtime.event(pid, :my_event)
:ok = Jido.Sensor.Runtime.event(pid, {:data_received, payload})
@spec start_link(keyword() | map()) :: GenServer.on_start()
Starts a Sensor.Runtime linked to the calling process.
Options
:sensor- Sensor module (required):config- Configuration map or keyword list for the sensor (default: %{}):context- Context map including:agent_ref(default: %{}):id- Instance ID (auto-generated if not provided)
Examples
{:ok, pid} = Jido.Sensor.Runtime.start_link(
sensor: MySensor,
config: %{interval: 5000},
context: %{agent_ref: agent_pid}
)