whileRunning<T> method

Future<T> whileRunning<T>(
  1. Future<T> work()
)

Completes on success, reports a failure, and stops on every exit.

The work result is returned unchanged; work errors are rethrown.

Implementation

Future<T> whileRunning<T>(Future<T> Function() work) async {
  try {
    final result = await work();
    complete();
    return result;
  } on Object {
    fail();
    rethrow;
  } finally {
    stop();
  }
}