OLD | NEW |
1 library async_periodictimer; | 1 library async_periodictimer; |
2 | 2 |
3 import 'dart:async'; | 3 import 'dart:async'; |
4 import 'package:unittest/unittest.dart'; | 4 import 'package:unittest/unittest.dart'; |
5 | 5 |
6 main(message, replyTo) { | 6 main(message, replyTo) { |
7 var command = message.first; | 7 var command = message.first; |
8 expect(command, 'START'); | 8 expect(command, 'START'); |
9 int counter = 0; | 9 int counter = 0; |
10 new Timer.periodic(const Duration(milliseconds: 10), (timer) { | 10 new Timer.periodic(const Duration(milliseconds: 10), (timer) { |
11 if (counter == 3) { | 11 if (counter == 3) { |
12 counter = 1024; | 12 counter = 1024; |
13 timer.cancel(); | 13 timer.cancel(); |
14 // Wait some more time to be sure callback won't be invoked any | 14 // Wait some more time to be sure callback won't be invoked any |
15 // more. | 15 // more. |
16 new Timer(const Duration(milliseconds: 30), () { | 16 new Timer(const Duration(milliseconds: 30), () { |
17 replyTo.send('DONE'); | 17 replyTo.send('DONE'); |
18 }); | 18 }); |
19 return; | 19 return; |
20 } | 20 } |
21 assert(counter < 3); | 21 assert(counter < 3); |
22 counter++; | 22 counter++; |
23 }); | 23 }); |
24 } | 24 } |
OLD | NEW |