suspendOnTopic method

  1. @override
Future<void> suspendOnTopic(
  1. String runId,
  2. String stepName,
  3. String topic, {
  4. DateTime? deadline,
  5. Map<String, Object?>? data,
})
override

Suspends runId while awaiting an event with topic.

If deadline is provided, the run should be considered due at that time even if an event is never received.

Implementation

@override
Future<void> suspendOnTopic(
  String runId,
  String stepName,
  String topic, {
  DateTime? deadline,
  Map<String, Object?>? data,
}) async {
  final state = _runs[runId];
  if (state == null) return;
  final metadata = _prepareSuspensionData(
    data,
    resumeAt: deadline,
    deadline: deadline,
    topic: topic,
  );
  _runs[runId] = state.copyWith(
    status: WorkflowStatus.suspended,
    waitTopic: topic,
    resumeAt: deadline,
    suspensionData: metadata,
    updatedAt: _clock.now(),
  );
  _suspendedTopics.putIfAbsent(topic, () => <String>{}).add(runId);
  if (deadline != null) {
    _due.putIfAbsent(deadline, () => <String>{}).add(runId);
  }
}