You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
store test [nfc]: Use async.elapse instead of await Future.delayed
This lets us simplify by cutting `async.flushMicrotasks` calls.
Saying `await Future.delayed` creates a timer, and then waits for that
timer. Waiting for the timer starts by flushing microtasks, then runs
any other timers due before the scheduled time (which can't exist when
the delay is Duration.zero), then moves on to timers scheduled for
right at the given delay. But for those timers with the exact same
scheduled time, it runs only the timers that were previously
scheduled. Any timers created by those microtasks or intermediate
timers, and scheduled for the exact time, remain in the queue behind
the timer created by that `Future.delayed`.
That's why these `await Future.delayed` lines had to be preceded by
`async.flushMicrotasks` calls: the timers they were meant to wait for
hadn't yet been created, but there were pending microtasks that would
create them.
By saying `async.elapse`, we step outside the timers. Because the
`elapse` call doesn't itself have a place in the timer queue, it can
keep waiting until every timer with the scheduled time has run -- no
matter how long a chain of microtasks and previous timers is involved
in creating that timer.
0 commit comments