1.9.0
Changes
The Disposable.awaitBeforeDispose()
API was intended to provide consumers with a way to delay disposal such that certain tasks could be completed before managed instances/dependencies were torn down. The intention was that the Disposable
APIs themselves would remain usable, even after dispose()
was called, so long as disposal hadn't started. Unfortunately, Disposable.isDisposedOrDisposing
would begin returning true
as soon as dispose()
was called, and our Disposable
APIs would throw if called after that point.
To address this, we've done a few things:
-
Changed the logic behind
isDisposing
(and consequentlyisDisposedOrDisposing
) such that it only becomestrue
when disposal has actually started. Based on current usages of this API, we do not expect any breakages from this change. -
Added a
isOrWillBeDisposed
getter – this should be used by consumers to guard their own public APIs so as to prevent additional tasks from being started. It will betrue
as soon as disposal is requested (i.e. as soon asdispose()
is called). -
Deprecated
isDisposing
andisDisposedOrDisposing
– the newly added getter above should be sufficient for consumers to guard their own APIs. -
Added a
onWillDispose()
lifecycle hook that, likeonDispose()
, can be overridden by extenders ofDisposable
. This handler will be called as soon as disposal is requested (i.e.dispose()
is called) but before disposal has started. TheFuture
returned from this method will be awaited, then allFuture
s registered viaawaitBeforeDispose()
will be awaited, and only then when disposal actually begin.
The result of these changes are that you may now actually delay disposal via awaitBeforeDispose()
(as was originally intended) and via onWillDispose()
. All of the Disposable
APIs will remain usable up until disposal actually begins.
Deprecations
The following two getters on the Disposable
class have been deprecated:
isDisposing
isDisposedOrDisposing
Consumers should now use Disposable.isOrWillBeDisposed
– it will be true
as soon as disposal is requested (i.e. when dispose()
is called) and will remain true while the instance is disposing, and when it has completed disposal.
Pull Requests
Notes created on Thursday, October 26 11:21 PM UTC