defer method
Defer the action execution, if the action is not already executed or canceled. Use onDefer to delay starting your executionDeferral until the action is ready to execute.
Example: asyncEvent.defer(asyncEvent.onDefer.then((_) { return doSomeAsyncThingThatDelaysTheEvent(); });
Implementation
void defer(Future<dynamic> executionDeferral) {
// Do nothing, it will be cancelled anyway.
if (cancelled) return;
// Don't allow more registrations.
if (isDone!) {
throw StateError('Cannot register. Action is complete.');
}
if (_waitingForDone!) {
throw StateError('Cannot register. Already waiting.');
}
// Register a future.
_executionDeferrals.add(executionDeferral);
}