| 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 import 'dart:async'; | 5 import 'dart:async'; |
| 6 import 'dart:isolate'; | 6 import 'dart:isolate'; |
| 7 | 7 |
| 8 var firstFunction; | 8 var firstFunction; |
| 9 var finishFunction; | 9 var finishFunction; |
| 10 | 10 |
| 11 void runFunctions() { | 11 void runFunctions() { |
| 12 try { | 12 try { |
| 13 firstFunction(); | 13 firstFunction(); |
| 14 } catch (e) { | 14 } catch (e) { |
| 15 new Timer(Duration.ZERO, finishFunction); | 15 new Timer(Duration.ZERO, finishFunction); |
| 16 throw; | 16 throw; |
| 17 } | 17 } |
| 18 } | 18 } |
| 19 | 19 |
| 20 void startTest(SendPort finishPort, replyPort) { | 20 void startTest(StreamSink finishSink) { |
| 21 firstFunction = () { throw new RuntimeError("ignore exception"); }; | 21 firstFunction = () { throw new RuntimeError("ignore exception"); }; |
| 22 finishFunction = () { finishPort.send("done"); }; | 22 finishFunction = () { finishSink.add("done"); finishPort.close(); }; |
| 23 new Timer(Duration.ZERO, runFunctions); | 23 new Timer(Duration.ZERO, runFunctions); |
| 24 } | 24 } |
| 25 | 25 |
| 26 runTest() { | 26 runTest() { |
| 27 port.receive(startTest); | 27 stream.single.then(startTest); |
| 28 } | 28 } |
| 29 | 29 |
| 30 bool globalErrorHandler(IsolateUnhandledException e) { | 30 bool globalErrorHandler(IsolateUnhandledException e) { |
| 31 return e.source is RuntimeError && e.source.message == "ignore exception"; | 31 return e.source is RuntimeError && e.source.message == "ignore exception"; |
| 32 } | 32 } |
| 33 | 33 |
| 34 main() { | 34 main() { |
| 35 var port = new ReceivePort(); | 35 var box = new MessageBox(); |
| 36 var timer; | 36 var timer; |
| 37 SendPort otherIsolate = spawnFunction(runTest, globalErrorHandler); | 37 StreamSink otherIsolate = streamSpawnFunction(runTest, globalErrorHandler); |
| 38 otherIsolate.send(port.toSendPort()); | 38 otherIsolate.add(box.sink); |
| 39 port.receive((msg, replyPort) { port.close(); timer.cancel(); }); | 39 otherIsolate.close(); |
| 40 box.stream.single.then((msg) { |
| 41 box.stream.close(); |
| 42 timer.cancel(); |
| 43 }); |
| 40 timer = new Timer(const Duration(seconds: 2), () { throw "failed"; }); | 44 timer = new Timer(const Duration(seconds: 2), () { throw "failed"; }); |
| 41 } | 45 } |
| OLD | NEW |