runAsync<T> method

  1. @override
Future<T> runAsync <T>(
  1. Future<T> callback(
    1. {Duration additionalTime: const Duration(milliseconds: 1000)}

    Runs a callback that performs real asynchronous work.

    This is intended for callers who need to call asynchronous methods where the methods spawn isolates or OS threads and thus cannot be executed synchronously by calling pump.

    If callback completes successfully, this will return the future returned by callback.

    If callback completes with an error, the error will be caught by the Flutter framework and made available via takeException, and this method will return a future that completes with null.

    Re-entrant calls to this method are not allowed; callers of this method are required to wait for the returned future to complete before calling this method again. Attempts to do otherwise will result in a TestFailure error being thrown.

    The additionalTime argument is used by the AutomatedTestWidgetsFlutterBinding implementation to increase the current timeout, if any. See AutomatedTestWidgetsFlutterBinding.addTime for details.


    Future<T> runAsync<T>(
      Future<T> callback(), {
      Duration additionalTime = const Duration(milliseconds: 1000),
    }) async {
      assert(() {
        if (!_runningAsyncTasks)
          return true;
        throw test_package.TestFailure(
            'Reentrant call to runAsync() denied.\n'
            'runAsync() was called, then before its future completed, it '
            'was called again. You must wait for the first returned future '
            'to complete before calling runAsync() again.'
      addTime(additionalTime); // doesn't do anything since we don't actually track the timeout, but just for correctness...
      _runningAsyncTasks = true;
      try {
        return await callback();
      } catch (error, stack) {
          exception: error,
          stack: stack,
          library: 'Flutter test framework',
          context: ErrorSummary('while running async test code'),
        return null;
      } finally {
        _runningAsyncTasks = false;