complete method

void complete ([dynamic value ])

Completes operation to value.

If value is a Future, this will complete to the result of that Future once it completes.

Implementation

void complete([value]) {
  if (_isCompleted) throw new StateError("Operation already completed");
  _isCompleted = true;

  if (value is! Future) {
    if (_isCanceled) return;
    _inner.complete(value);
    return;
  }

  if (_isCanceled) {
    // Make sure errors from [value] aren't top-leveled.
    value.catchError((_) {});
    return;
  }

  value.then((result) {
    if (_isCanceled) return;
    _inner.complete(result);
  }, onError: (error, stackTrace) {
    if (_isCanceled) return;
    _inner.completeError(error, stackTrace);
  });
}