resume method

Future<Null> resume()

Public method to resume the module.

This should put the module back into its normal state after the module was suspended.

Only initiates the resume process when the module is in the suspended state. If the module is in the resuming state a warning is logged and the method is a noop. If the module is in any other state, a StateError is thrown.

The Future values of all children resume calls will be awaited. The first child to return an error value will emit the error on the didResume lifecycle stream. The returned Future will also resolve with this exception.

If an Exception is thrown during the call to onResume it will be emitted on the didResume lifecycle stream. The returned Future will also resolve with this exception.

If an error or exception is thrown during the call to the parent onResume lifecycle method it will be emitted on the didResume lifecycle stream. The error will also be returned by resume.

Implementation

Future<Null> resume() {
  if (isOrWillBeDisposed) {
    return _buildDisposedOrDisposingResponse(methodName: 'resume');
  }

  if (isLoaded || isResuming) {
    return _buildNoopResponse(
        isTransitioning: isResuming,
        methodName: 'resume',
        currentState:
            isResuming ? LifecycleState.resuming : LifecycleState.loaded);
  }

  if (!(isSuspended || isSuspending)) {
    return _buildIllegalTransitionResponse(
        targetState: LifecycleState.loaded,
        allowedStates: [LifecycleState.suspended, LifecycleState.suspending]);
  }

  Future<Null>? pendingTransition;
  if (_transition != null && !_transition!.isCompleted) {
    pendingTransition = _transition!.future.then((_) {
      _activeSpan = _startTransitionSpan('resume');
    });
  } else {
    _activeSpan = _startTransitionSpan('resume');
  }

  _state = LifecycleState.resuming;
  final transition = Completer<Null>();
  _transition = transition;

  _resume(pendingTransition)
      .then(transition.complete)
      .catchError((error, trace) {
    transition.completeError(error, trace);
    _activeSpan?.setTag('error', true);
  }).whenComplete(() {
    _activeSpan?.finish();
    _activeSpan = null;
  });

  return _transition!.future;
}