isOrWillBeDisposed property
Whether the disposal of this object has been requested, is in progress, or is complete.
This will become true as soon as the dispose method is called and will
remain true forever.
Recommended usage of this boolean is to guard public APIs such that all
calls after disposal has been requested (via dispose) are rejected:
Response sendRequest() async {
if (isOrWillBeDisposed) {
throw new StateError(
'sendRequest() cannot be called, object is disposing');
}
...
}
Implementation
bool get isOrWillBeDisposed =>
_state == DisposableState.awaitingDisposal ||
_state == DisposableState.disposing ||
_state == DisposableState.disposed;