step<T extends Object?> method

void step<T extends Object?>(
  1. SagaStep<T> step
)

Registers a saga step to be executed.

Steps are executed in the order they are registered. Each step can have a different return type T, which is passed to its compensation function.

Type safety: The generic type parameter T in SagaStep<T> ensures that the return value from SagaStep.execute matches the input parameter to SagaStep.compensate. This prevents type mismatches at runtime.

Parameters:

  • step: A SagaStep of T with execute and compensate functions

Example:

saga.step(SagaStep<String>(
  name: 'Send Email',
  execute: () async => await emailService.send(recipient),
  compensate: (messageId) async => await emailService.cancel(messageId),
));

Implementation

void step<T extends Object?>(SagaStep<T> step) => _steps.add(step);