addDisposable<T> method
T
addDisposable<T>(
- T disposable
Registers disposable
for disposal when dispose is called later.
Prefer typed functions whenever possible, as this is megamorphic: addEventSink addStreamSubscription addFunction
Implementation
T addDisposable<T>(T disposable) {
// TODO(google): `disposable_` is a workaround to make this code
// strong-clean. We should be able to get rid of it once dartbug.com/26439
// is addressed in the language.
dynamic disposable_ = disposable;
if (disposable_ is Disposable) {
_disposeDisposables.add(disposable as Disposable);
_checkIfAlreadyDisposed();
} else if (disposable_ is StreamSubscription) {
addStreamSubscription(disposable_);
} else if (disposable_ is EventSink) {
addEventSink(disposable_);
} else if (disposable_ is DisposeFunction) {
addFunction(disposable_);
} else {
throw ArgumentError.value(disposable, 'disposable');
}
return disposable;
}