cancel method

void cancel()

Cancels this token, invoking all registered onCancel callbacks.

Idempotent — cancelling an already-cancelled token is a no-op.

Implementation

void cancel() {
  if (_isCancelled) return;
  _isCancelled = true;
  for (final cb in List.of(_callbacks)) {
    try {
      cb();
    } catch (_) {}
  }
  _callbacks.clear();
}