run<T> method Null safety

T run<T>(
  1. T callback(
    1. FakeAsync self
    )
)

Runs callback in a Zone where all asynchrony is controlled by this.

All Futures, Streams, Timers, microtasks, and other time-based asynchronous features used within callback are controlled by calls to elapse rather than the passing of real time.

The clock property will be set to a clock that reports the fake elapsed time. By default, it starts at the time the FakeAsync was created (according to clock.now()), but this can be controlled by passing initialTime to new FakeAsync.

Calls callback with this as argument and returns its result.

Note: it's usually more convenient to use fakeAsync rather than creating a FakeAsync object and calling run manually.

Implementation

T run<T>(T Function(FakeAsync self) callback) =>
    runZoned(() => withClock(_clock, () => callback(this)),
        zoneSpecification: ZoneSpecification(
            createTimer: (_, __, ___, duration, callback) =>
                _createTimer(duration, callback, false),
            createPeriodicTimer: (_, __, ___, duration, callback) =>
                _createTimer(duration, callback, true),
            scheduleMicrotask: (_, __, ___, microtask) =>
                _microtasks.add(microtask)));