cancel method

void cancel()

Synchronously cancel the action. Once called, all future calls to cancelIf and defer will have no effect, nor will any futures previously registered with cancelIf be awaited before resolving the onDefer and onDone futures.

Implementation

void cancel() {
  if (cancelled) return;

  // Don't allow more registrations.
  if (isDone!) {
    throw StateError('Cannot register. Action is complete.');
  }

  if (_waitingForDone!) {
    throw StateError('Cannot register. Already waiting.');
  }

  _syncCancelled = true;
  _futureCancellations
    ..clear()
    ..add(Future.value(true));
}