This repository was archived by the owner on Feb 22, 2018. It is now read-only.
File tree 2 files changed +41
-0
lines changed
2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -68,6 +68,25 @@ microLeap() {
68
68
*/
69
69
isAsyncQueueEmpty () => _asyncQueue.isEmpty;
70
70
71
+ /**
72
+ * Returns whether there are outstanding timers.
73
+ */
74
+ isTimerQueueEmpty () => _timerQueue.isEmpty;
75
+
76
+ /**
77
+ * Returns whether there are outstanding non-periodic timers.
78
+ */
79
+ isNonPeriodicTimerQueueEmpty () => _timerQueue
80
+ .where ((_TimerSpec spec) => ! spec.periodic)
81
+ .isEmpty;
82
+
83
+ /**
84
+ * Returns whether there are outstanding periodic timers.
85
+ */
86
+ isPeriodicTimerQueueEmpty () => _timerQueue
87
+ .where ((_TimerSpec spec) => spec.periodic)
88
+ .isEmpty;
89
+
71
90
/**
72
91
* Simulates a clock tick by running any scheduled timers. Can only be used
73
92
* in [async] tests.Clock tick will call [microLeap] to process the microtask
Original file line number Diff line number Diff line change @@ -332,6 +332,28 @@ void main() {
332
332
(_) => dump ("i never run" ));
333
333
})).toThrow ('1 active timer(s) are still in the queue.' );
334
334
});
335
+
336
+ it ('should report no timers when there are none' , async (() {
337
+ expect (isTimerQueueEmpty ()).toBe (true );
338
+ expect (isNonPeriodicTimerQueueEmpty ()).toBe (true );
339
+ expect (isPeriodicTimerQueueEmpty ()).toBe (true );
340
+ }));
341
+
342
+ it ('should report remaining non-periodic timers' , async (() {
343
+ new Future (() => null );
344
+ expect (isTimerQueueEmpty ()).toBe (false );
345
+ expect (isNonPeriodicTimerQueueEmpty ()).toBe (false );
346
+ expect (isPeriodicTimerQueueEmpty ()).toBe (true );
347
+ clockTick ();
348
+ }));
349
+
350
+ it ('should report remaining periodic timers' , async (() {
351
+ var t = new Timer .periodic (new Duration (seconds: 1 ), (_) => null );
352
+ expect (isTimerQueueEmpty ()).toBe (false );
353
+ expect (isNonPeriodicTimerQueueEmpty ()).toBe (true );
354
+ expect (isPeriodicTimerQueueEmpty ()).toBe (false );
355
+ t.cancel ();
356
+ }));
335
357
});
336
358
});
337
359
});
You can’t perform that action at this time.
0 commit comments