onAbort method
Registers one notification and returns an idempotent removal function.
Notifications run asynchronously in the registration's zone, including registrations made after cancellation. Removing a queued notification suppresses it. A notification is not confirmation that work has stopped.
Implementation
@override
void Function() onAbort(void Function() listener) {
final registration = _AbortRegistration(listener, Zone.current);
(_listeners ??= {}).add(registration);
try {
if (_notified || aborted) {
_notify();
} else if (!_armed) {
_armed = true;
armAbort();
// An adapter may synchronously observe an abort while arming.
if (aborted) notifyAbort();
}
} catch (_) {
_remove(registration);
rethrow;
}
// Keeping this function is an ordinary Dart root for the token.
return () => _remove(registration);
}