cancel method

void cancel([
  1. String reason = 'Operation cancelled'
])

Cancels all operations using this token

reason - Optional message explaining why the operation was cancelled

Implementation

void cancel([String reason = 'Operation cancelled']) {
  if (isCancelled) {
    debugPrint('⚠️ CancelToken already cancelled. '
        'Previous reason: $_cancelReason, new reason: $reason');
    return;
  }

  _cancelReason = reason;
  _stackTrace = StackTrace.current;
  _completer?.complete();

  debugPrint('🚫 CancelToken cancelled: $reason');
}