Jido.Signal.Bus.MiddlewarePipeline (Jido Signal v1.0.0)

View Source

Handles execution of middleware chains for signal bus operations.

This module provides functions to execute middleware callbacks in sequence, allowing each middleware to transform signals or control the flow of execution.

Summary

Functions

Executes the after_dispatch middleware chain.

Executes the after_publish middleware chain.

Executes the before_dispatch middleware chain for a single signal and subscriber.

Executes the before_publish middleware chain.

Initializes a list of middleware modules with their options.

Types

context()

@type context() :: Jido.Signal.Bus.Middleware.context()

middleware_config()

@type middleware_config() :: {module(), term()}

Functions

after_dispatch(middleware_configs, signal, subscriber, result, context)

Executes the after_dispatch middleware chain.

This is called for side effects only after a signal has been dispatched.

after_publish(middleware_configs, signals, context)

@spec after_publish([middleware_config()], [Jido.Signal.t()], context()) :: :ok

Executes the after_publish middleware chain.

This is called for side effects only - signals cannot be modified.

before_dispatch(middleware_configs, signal, subscriber, context)

@spec before_dispatch(
  [middleware_config()],
  Jido.Signal.t(),
  Jido.Signal.Bus.Subscriber.t(),
  context()
) ::
  {:ok, Jido.Signal.t()} | :skip | {:error, term()}

Executes the before_dispatch middleware chain for a single signal and subscriber.

Returns the potentially modified signal, or indicates if dispatch should be skipped/halted.

before_publish(middleware_configs, signals, context)

@spec before_publish([middleware_config()], [Jido.Signal.t()], context()) ::
  {:ok, [Jido.Signal.t()]} | {:error, term()}

Executes the before_publish middleware chain.

Stops execution if any middleware returns :halt.

init_middleware(middleware_specs)

@spec init_middleware([{module(), keyword()}]) ::
  {:ok, [middleware_config()]} | {:error, term()}

Initializes a list of middleware modules with their options.

Returns a list of {module, state} tuples that can be used in the pipeline.