manageCompleter<T> method

  1. @mustCallSuper
  2. @override
Completer<T> manageCompleter <T>(Completer<T> completer)
@mustCallSuper, override

Ensure that a completer is completed when the object is disposed.

If the completer has not been completed by the time the object is disposed, it will be completed with an ObjectDisposedException error.

Implementation

@mustCallSuper
@override
Completer<T> manageCompleter<T>(Completer<T> completer) {
  _throwOnInvalidCall('manageCompleter', 'completer', completer);
  _logManageMessage(completer);

  var disposable = new ManagedDisposer(() async {
    if (!completer.isCompleted) {
      completer.completeError(new ObjectDisposedException());
    }
  });
  _internalDisposables.add(disposable);

  completer.future.catchError((e) {
    // ignore: deprecated_member_use
    if (!isDisposedOrDisposing) {
      _logUnmanageMessage(completer);
      _internalDisposables.remove(disposable);
    }
  }).then((_) {
    // ignore: deprecated_member_use
    if (!isDisposedOrDisposing) {
      _logUnmanageMessage(completer);
      _internalDisposables.remove(disposable);
    }
  });

  return completer;
}