Interface ISagaTimeout<TMessage>
- Namespace
- Excalibur.Saga.Abstractions
- Assembly
- Excalibur.Saga.dll
Defines a strongly-typed handler for saga timeout messages. Sagas implement this interface to declare which timeout types they handle, enabling the framework to route delivered timeouts directly to the correct handler method.
public interface ISagaTimeout<in TMessage>
Type Parameters
TMessageThe timeout message type. This should match the type parameter used when scheduling the timeout via
RequestTimeoutAsync<TMessage>(delay, cancellationToken).
Remarks
This interface follows the NServiceBus IHandleTimeouts<T> pattern, providing
a clean separation between normal event handling (HandleAsync) and timeout
handling. A saga can implement multiple ISagaTimeout<T> interfaces for
different timeout message types.
When a timeout is delivered and the saga implements ISagaTimeout<T> for
the timeout's message type, the framework calls HandleTimeoutAsync(TMessage, CancellationToken) instead
of the general HandleAsync method. If no matching ISagaTimeout<T>
is found, the timeout falls through to normal event handling.
Usage:
public class OrderSaga : SagaBase<OrderSagaState>,
ISagaTimeout<PaymentTimeout>,
ISagaTimeout<ShippingTimeout>
{
public Task HandleTimeoutAsync(PaymentTimeout message, CancellationToken cancellationToken)
{
// Cancel the order due to payment timeout
State.Status = "Cancelled";
MarkCompleted();
return Task.CompletedTask;
}
public Task HandleTimeoutAsync(ShippingTimeout message, CancellationToken cancellationToken)
{
// Escalate shipping delay
return SendCommandAsync(new EscalateShipping(State.OrderId), cancellationToken);
}
}
Methods
HandleTimeoutAsync(TMessage, CancellationToken)
Handles a timeout message that was previously scheduled via
RequestTimeoutAsync<TMessage>.
Task HandleTimeoutAsync(TMessage message, CancellationToken cancellationToken)
Parameters
messageTMessageThe timeout message containing any data provided at scheduling time.
cancellationTokenCancellationTokenToken to monitor for cancellation requests.
Returns
- Task
A task representing the asynchronous timeout handling operation.