View Source Jido.Workflow.Closure (Jido v1.0.0)
Provides functionality to create closures around Jido Workflows (Actions).
This module allows for partial application of context and options to actions, creating reusable workflow closures that can be executed with different parameters.
Summary
Functions
Creates an async closure around a action with pre-applied context and options.
Creates a closure around a action with pre-applied context and options.
Types
@type action() :: Jido.Workflow.action()
@type closure() :: (params() -> {:ok, map()} | {:error, Jido.Error.t()})
@type context() :: Jido.Workflow.context()
@type params() :: Jido.Workflow.params()
@type run_opts() :: Jido.Workflow.run_opts()
Functions
@spec async_closure(action(), context(), run_opts()) :: (params() -> Jido.Workflow.async_ref())
Creates an async closure around a action with pre-applied context and options.
Parameters
action
: The action module to create an async closure for.context
: The context to be applied to the action (default: %{}).opts
: The options to be applied to the action execution (default: []).
Returns
A function that takes params and returns an async reference.
Examples
iex> async_closure = Jido.Workflow.Closure.async_closure(MyAction, %{user_id: 123}, [timeout: 10_000])
iex> async_ref = async_closure.(%{input: "test"})
iex> Jido.Workflow.await(async_ref)
{:ok, %{result: "processed test"}}
Creates a closure around a action with pre-applied context and options.
Parameters
action
: The action module to create a closure for.context
: The context to be applied to the action (default: %{}).opts
: The options to be applied to the action execution (default: []).
Returns
A function that takes params and returns the result of running the action.
Examples
iex> closure = Jido.Workflow.Closure.closure(MyAction, %{user_id: 123}, [timeout: 10_000])
iex> closure.(%{input: "test"})
{:ok, %{result: "processed test"}}