getManagedDelayedFuture<T> method
Creates a Future that will complete, with the value
returned by callback
, after the given amount of time has elapsed.
If the object is disposed before the time has elapsed the future
will complete with an ObjectDisposedException
error.
Implementation
@mustCallSuper
@override
Future<T> getManagedDelayedFuture<T>(Duration duration, T callback()) {
_throwOnInvalidCall2(
'getManagedDelayedFuture', 'duration', 'callback', duration, callback);
var completer = Completer<T>();
var timer =
_ObservableTimer(duration, () => completer.complete(callback()));
var disposable = ManagedDisposer(() async {
timer.cancel();
completer.completeError(ObjectDisposedException());
});
_logManageMessage(completer.future);
_internalDisposables.add(disposable);
timer.didConclude.then((Null _) {
if (!_isDisposedOrDisposing) {
_logUnmanageMessage(completer.future);
_internalDisposables.remove(disposable);
}
});
return completer.future;
}