onCancel method

void Function() onCancel(
  1. void listener()
)

Registers a non-throwing callback and returns its removal function. Already canceled tokens invoke the callback immediately.

Implementation

void Function() onCancel(void Function() listener) {
  if (isCanceled) {
    listener();
    return () {};
  }
  _listeners.add(listener);
  return () => _listeners.remove(listener);
}