Path: redb-route/redb.Route/Processors/DelegateProcessor.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/Processors/DelegateProcessor.cs
----
using redb.Route.Abstractions;
namespace redb.Route.Processors;
///
/// Processes a message exchange asynchronously using a delegate function.
/// Simplest processor — wraps a user-provided Func.
///
public class DelegateProcessor : IProcessor
{
private readonly Func _action;
/// Creates a processor from an async delegate.
/// The async action to execute on each exchange.
public DelegateProcessor(Func action)
{
_action = action ?? throw new ArgumentNullException(nameof(action));
}
/// Creates a processor from a synchronous delegate.
/// The synchronous action to execute on each exchange.
public DelegateProcessor(Action action)
{
ArgumentNullException.ThrowIfNull(action);
_action = (ex, _) => { action(ex); return Task.CompletedTask; };
}
///
public Task Process(IExchange exchange, CancellationToken ct = default)
=> _action(exchange, ct);
}