cancel method
Implementation
@override
void cancel() {
if (_isCancellationRequested) {
// Prevent to call listeners twice
return;
}
_isCancellationRequested = true;
if (_cancelListeners.isNotEmpty) {
FCancellationException cancellationException;
try {
throw FCancellationException();
} catch (e) {
// Got stack trace in this way
cancellationException = e as FCancellationException;
}
final errors = <FException>[];
// Release callback. We do not need its anymore
final cancelListeners =
List<FCancellationTokenCallback>.from(_cancelListeners);
for (final cancelListener in cancelListeners) {
try {
cancelListener(cancellationException);
} catch (e) {
errors.add(FException.wrapIfNeeded(e));
}
}
FExceptionAggregate.throwIfNeeded(errors);
}
}