OLD | NEW |
| (Empty) |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | |
2 // for details. All rights reserved. Use of this source code is governed by a | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 import 'package:async_helper/async_helper.dart'; | |
6 import "package:expect/expect.dart"; | |
7 import 'dart:async'; | |
8 | |
9 Future testOneScheduleMicrotask() { | |
10 var completer = new Completer(); | |
11 Timer.run(() { | |
12 scheduleMicrotask(completer.complete); | |
13 }); | |
14 return completer.future; | |
15 } | |
16 | |
17 Future testMultipleScheduleMicrotask() { | |
18 var completer = new Completer(); | |
19 Timer.run(() { | |
20 const TOTAL = 10; | |
21 int done = 0; | |
22 for (int i = 0; i < TOTAL; i++) { | |
23 scheduleMicrotask(() { | |
24 done++; | |
25 if (done == TOTAL) completer.complete(); | |
26 ; | |
27 }); | |
28 } | |
29 }); | |
30 return completer.future; | |
31 } | |
32 | |
33 Future testScheduleMicrotaskThenTimer() { | |
34 var completer = new Completer(); | |
35 Timer.run(() { | |
36 bool scheduleMicrotaskDone = false; | |
37 scheduleMicrotask(() { | |
38 Expect.isFalse(scheduleMicrotaskDone); | |
39 scheduleMicrotaskDone = true; | |
40 }); | |
41 Timer.run(() { | |
42 Expect.isTrue(scheduleMicrotaskDone); | |
43 completer.complete(); | |
44 }); | |
45 }); | |
46 return completer.future; | |
47 } | |
48 | |
49 Future testTimerThenScheduleMicrotask() { | |
50 var completer = new Completer(); | |
51 Timer.run(() { | |
52 bool scheduleMicrotaskDone = false; | |
53 Timer.run(() { | |
54 Expect.isTrue(scheduleMicrotaskDone); | |
55 completer.complete(); | |
56 }); | |
57 scheduleMicrotask(() { | |
58 Expect.isFalse(scheduleMicrotaskDone); | |
59 scheduleMicrotaskDone = true; | |
60 }); | |
61 }); | |
62 return completer.future; | |
63 } | |
64 | |
65 Future testTimerThenScheduleMicrotaskChain() { | |
66 var completer = new Completer(); | |
67 Timer.run(() { | |
68 const TOTAL = 10; | |
69 int scheduleMicrotaskDone = 0; | |
70 Timer.run(() { | |
71 Expect.equals(TOTAL, scheduleMicrotaskDone); | |
72 completer.complete(); | |
73 }); | |
74 Future scheduleMicrotaskCallback() { | |
75 scheduleMicrotaskDone++; | |
76 if (scheduleMicrotaskDone != TOTAL) { | |
77 scheduleMicrotask(scheduleMicrotaskCallback); | |
78 } | |
79 } | |
80 | |
81 scheduleMicrotask(scheduleMicrotaskCallback); | |
82 }); | |
83 return completer.future; | |
84 } | |
85 | |
86 main() { | |
87 asyncStart(); | |
88 testOneScheduleMicrotask() | |
89 .then((_) => testMultipleScheduleMicrotask()) | |
90 .then((_) => testScheduleMicrotaskThenTimer()) | |
91 .then((_) => testTimerThenScheduleMicrotask()) | |
92 .then((_) => testTimerThenScheduleMicrotaskChain()) | |
93 .then((_) => asyncEnd()); | |
94 } | |
OLD | NEW |