| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library test; | 5 library test; |
| 6 | 6 |
| 7 import 'package:expect/expect.dart'; | 7 import 'package:expect/expect.dart'; |
| 8 import 'dart:async'; | 8 import 'dart:async'; |
| 9 import 'dart:isolate'; | 9 import 'dart:isolate'; |
| 10 import '../async_helper.dart'; |
| 10 | 11 |
| 11 runTest() { | 12 runTest() { |
| 12 IsolateSink mainIsolate; | 13 IsolateSink mainIsolate; |
| 13 stream.listen((msg) { | 14 stream.listen((msg) { |
| 14 mainIsolate = msg; | 15 mainIsolate = msg; |
| 15 throw new UnsupportedError("ignore exception"); | 16 throw new UnsupportedError("ignore exception"); |
| 16 }, onDone: () { | 17 }, onDone: () { |
| 17 mainIsolate.add("received done"); | 18 mainIsolate.add("received done"); |
| 18 mainIsolate.close(); | 19 mainIsolate.close(); |
| 19 }); | 20 }); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 30 var timer = new Timer(const Duration(seconds: 2), () { throw "failed"; }); | 31 var timer = new Timer(const Duration(seconds: 2), () { throw "failed"; }); |
| 31 | 32 |
| 32 var box = new MessageBox(); | 33 var box = new MessageBox(); |
| 33 IsolateSink otherIsolate = streamSpawnFunction(runTest, globalErrorHandler); | 34 IsolateSink otherIsolate = streamSpawnFunction(runTest, globalErrorHandler); |
| 34 otherIsolate.add(box.sink); | 35 otherIsolate.add(box.sink); |
| 35 // The previous event should have been handled entirely, but the current | 36 // The previous event should have been handled entirely, but the current |
| 36 // implementations don't guarantee that and might mix the done event with | 37 // implementations don't guarantee that and might mix the done event with |
| 37 // the handling of the previous event. We therefore delay the closing. | 38 // the handling of the previous event. We therefore delay the closing. |
| 38 // Note: if the done is sent too early it won't lead to failing tests, but | 39 // Note: if the done is sent too early it won't lead to failing tests, but |
| 39 // just won't make sure that the globalErrorHandler works. | 40 // just won't make sure that the globalErrorHandler works. |
| 40 new Timer(const Duration(milliseconds: 10), otherIsolate.close); | 41 asyncStart(); |
| 42 new Timer(const Duration(milliseconds: 10), () { |
| 43 otherIsolate.close(); |
| 44 asyncEnd(); |
| 45 }); |
| 46 asyncStart(); |
| 41 box.stream.single.then((msg) { | 47 box.stream.single.then((msg) { |
| 42 Expect.equals("received done", msg); | 48 Expect.equals("received done", msg); |
| 43 timer.cancel(); | 49 timer.cancel(); |
| 44 keepRunningBox.stream.close(); | 50 keepRunningBox.stream.close(); |
| 51 asyncEnd(); |
| 45 }); | 52 }); |
| 46 } | 53 } |
| OLD | NEW |