File tree Expand file tree Collapse file tree 1 file changed +16
-4
lines changed Expand file tree Collapse file tree 1 file changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -305,15 +305,22 @@ final class ClockController {
305305 Duration ? minimumStep,
306306 }) async {
307307 final deadline = timeout != null ? clock.fromNowBy (timeout) : null ;
308- while (_pendingTimers.isNotEmpty &&
308+
309+ bool shouldLoop () =>
310+ _pendingTimers.isNotEmpty &&
309311 (deadline == null ||
310- _pendingTimers.first._elapsesAtInFakeTime.isBefore (deadline))) {
312+ _pendingTimers.first._elapsesAtInFakeTime.isBefore (deadline));
313+
314+ while (shouldLoop ()) {
311315 if (await condition ()) {
312316 return ;
313317 }
314318
315319 // Wait for all microtasks to run
316320 await _waitForMicroTasks ();
321+ if (! shouldLoop ()) {
322+ break ;
323+ }
317324
318325 // Jump into the future, until the point in time that the next timer is
319326 // pending.
@@ -371,10 +378,15 @@ final class ClockController {
371378 /// moving backwards in time. That allows [elapseTime] to be called with
372379 /// a zero duration.
373380 Future <void > _elapseTo (DateTime futureTime) async {
374- while (_pendingTimers.isNotEmpty &&
375- _pendingTimers.first._elapsesAtInFakeTime.isBefore (futureTime)) {
381+ bool shouldLoop () =>
382+ _pendingTimers.isNotEmpty &&
383+ _pendingTimers.first._elapsesAtInFakeTime.isBefore (futureTime);
384+ while (shouldLoop ()) {
376385 // Wait for all microtasks to run
377386 await _waitForMicroTasks ();
387+ if (! shouldLoop ()) {
388+ break ;
389+ }
378390
379391 // Jump into the future, until the point in time that the next timer is
380392 // pending.
You can’t perform that action at this time.
0 commit comments