Path: redb-route/redb.Route/Definitions/ProcessActionDefinition.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route/Definitions/ProcessActionDefinition.cs
----
using redb.Route.Abstractions;
using redb.Route.Core;
using redb.Route.Processors;
namespace redb.Route.Definitions;
///
/// Leaf definition that executes a synchronous delegate on the exchange.
///
public sealed class ProcessActionDefinition : ProcessorDefinition
{
private readonly Action _action;
/// Creates a definition for a synchronous processing action.
/// Synchronous action to execute on each exchange.
public ProcessActionDefinition(Action action)
{
ArgumentNullException.ThrowIfNull(action);
_action = action;
}
///
public override IProcessor CreateProcessor(IRouteContext context)
=> new DelegateProcessor(_action);
}
///
/// Leaf definition that executes an asynchronous delegate on the exchange.
///
public sealed class ProcessAsyncDefinition : ProcessorDefinition
{
private readonly Func _action;
/// Creates a definition for an asynchronous processing action.
/// Async action to execute on each exchange.
public ProcessAsyncDefinition(Func action)
{
ArgumentNullException.ThrowIfNull(action);
_action = action;
}
///
public override IProcessor CreateProcessor(IRouteContext context)
=> new DelegateProcessor(_action);
}
///
/// Leaf definition that returns a pre-built instance directly.
///
public sealed class ProcessInstanceDefinition : ProcessorDefinition
{
private readonly IProcessor _processor;
/// Creates a definition wrapping an existing processor instance.
/// Pre-built processor to use.
public ProcessInstanceDefinition(IProcessor processor)
{
ArgumentNullException.ThrowIfNull(processor);
_processor = processor;
}
///
public override IProcessor CreateProcessor(IRouteContext context)
=> _processor;
}