manageAndReturnTypedDisposable<T extends Disposable> method
- @mustCallSuper
- @override
- T disposable
override
Automatically dispose another object when this object is disposed.
This method is an extension to manageAndReturnDisposable
and returns the
passed in Disposable as its original type in addition to handling its
disposal. The method should be used when a variable is set and should
conditionally be managed for disposal. The most common case will be dealing
with optional parameters:
class MyDisposable extends Disposable {
// This object also extends disposable
MyObject _internal;
MyDisposable({MyObject optional}) {
// If optional is injected, we should not manage it.
// If we create our own internal reference we should manage it.
_internal = optional ??
manageAndReturnTypedDisposable(new MyObject());
}
// ...
}
A null parameter will result in a null return value.
Implementation
@mustCallSuper
@override
T manageAndReturnTypedDisposable<T extends Disposable>(T disposable) {
_throwOnInvalidCall('manageAndReturnDisposable', 'disposable', disposable);
manageDisposable(disposable);
return disposable;
}