Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 library async_cancellingisolate; | |
| 2 | |
| 3 import 'dart:async'; | |
| 4 import 'package:unittest/unittest.dart'; | |
| 5 | |
| 6 main(message, replyTo) { | |
| 7 var command = message[0]; | |
|
terry
2015/03/04 15:26:48
Should this be message.first (similar to other tes
| |
| 8 expect(command, 'START'); | |
| 9 bool shot = false; | |
|
terry
2015/03/04 15:26:48
NIT: probably don't need bool because of l-value.
| |
| 10 var oneshot; | |
| 11 var periodic; | |
| 12 periodic = new Timer.periodic(const Duration(milliseconds: 10), (timer) { | |
| 13 expect(shot, isFalse); | |
| 14 shot = true; | |
| 15 expect(timer, same(periodic)); | |
| 16 periodic.cancel(); | |
| 17 oneshot.cancel(); | |
| 18 // Wait some more time to be sure callbacks won't be invoked any | |
| 19 // more. | |
| 20 new Timer(const Duration(milliseconds: 50), () { | |
| 21 replyTo.send('DONE'); | |
| 22 }); | |
| 23 }); | |
| 24 // We launch the oneshot timer after the periodic timer. Otherwise a | |
| 25 // (very long) context switch could make this test flaky: assume the | |
| 26 // oneshot timer is created first and then there is a 30ms context switch. | |
| 27 // when the periodic timer is scheduled it would execute after the oneshot. | |
| 28 oneshot = new Timer(const Duration(milliseconds: 30), () { | |
| 29 fail('Should never be invoked'); | |
| 30 }); | |
| 31 } | |
| OLD | NEW |