cancel method

void cancel([
  1. Object? reason
])

Cancels the token with an optional reason.

Implementation

void cancel([Object? reason]) {
  if (token._isCancelled) return;
  token._isCancelled = true;
  token._reason = reason;
  if (!token._completer.isCompleted) {
    token._completer.complete();
  }
}