waitUntil method

void waitUntil(
  1. Future<void> task
)

Keeps task alive without delaying the response.

Tasks may register more tasks before they complete. Invocation-aware handlers wait for the complete task tree before disposing their modules.

Implementation

void waitUntil(Future<void> task) {
  final tasks = _tasks;
  if (tasks == null) {
    _observeTask(task);
    throw StateError(
      'ServerInvocation.empty cannot keep background work alive.',
    );
  }
  if (_closed) {
    throw StateError('The server invocation is already complete.');
  }
  tasks.add(
    task.then<_InvocationFailure?>(
      (_) => null,
      onError: (Object error, StackTrace stackTrace) =>
          _InvocationFailure(error, stackTrace),
    ),
  );
  if (!_registerWithHost(task, backgroundTask: true)) {
    _hasUnhostedTask = true;
  }
}