step<T> method

  1. @override
Future<T> step<T>(
  1. String name,
  2. Future<T> action(), {
  3. Future<void> compensate(
    1. T result
    )?,
  4. RetryPolicy retry = RetryPolicy.none,
  5. String serialize(
    1. T value
    )?,
  6. T deserialize(
    1. String data
    )?,
})
override

Executes a named step with checkpoint/resume semantics.

  • name: Human-readable step name (used as checkpoint key).
  • action: The function to execute. Should contain a single side effect.
  • compensate: Optional compensation function for saga rollback. Receives the step result as a parameter, enabling direct access to the result without mutable variable workarounds.
  • retry: Retry policy for this step. Defaults to no retry.
  • serialize: Custom serializer to convert the step result to a string for checkpoint persistence. If omitted, jsonEncode(result) is used.
  • deserialize: Custom deserializer to reconstruct the step result from the persisted string on recovery. If omitted, jsonDecode + cast is used, which only works for primitive types. Required for custom object types.

Returns the result of action (or the cached result on resume).

Implementation

@override
Future<T> step<T>(
  String name,
  Future<T> Function() action, {
  Future<void> Function(T result)? compensate,
  RetryPolicy retry = RetryPolicy.none,
  String Function(T value)? serialize,
  T Function(String data)? deserialize,
}) {
  validateIdentifier(name, 'name');
  return _executor.executeStep<T>(
    name,
    action,
    serialize: serialize,
    deserialize: deserialize,
    retryPolicy: retry,
    compensate: compensate,
  );
}