OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2014, 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 "dart:isolate"; |
| 6 import "dart:async"; |
| 7 import "package:async_helper/async_helper.dart"; |
| 8 |
| 9 isomain1(replyPort) { |
| 10 RawReceivePort port = new RawReceivePort(); |
| 11 port.handler = (v) { |
| 12 replyPort.send(v); |
| 13 port.close(); |
| 14 }; |
| 15 replyPort.send(port.sendPort); |
| 16 } |
| 17 |
| 18 main(){ |
| 19 asyncStart(); |
| 20 RawReceivePort reply = new RawReceivePort(); |
| 21 Isolate isolate; |
| 22 Capability resume; |
| 23 var completer = new Completer(); // Completed by first reply from isolate. |
| 24 reply.handler = completer.complete; |
| 25 Isolate.spawn(isomain1, reply.sendPort).then((Isolate iso) { |
| 26 isolate = iso; |
| 27 resume = isolate.pause(); |
| 28 return completer.future; |
| 29 }).then((echoPort) { |
| 30 // Isolate has been created, and first response has been returned. |
| 31 echoPort.send(24); |
| 32 reply.handler = (v) { |
| 33 throw "RESPONSE WHILE PAUSED?!?"; |
| 34 }; |
| 35 return new Future.delayed(const Duration(milliseconds: 250)); |
| 36 }).then((_) { |
| 37 reply.handler = (v) { |
| 38 if (v != 24) throw "WRONG ANSWER!"; |
| 39 reply.close(); |
| 40 asyncEnd(); |
| 41 }; |
| 42 isolate.resume(resume); |
| 43 }); |
| 44 } |
OLD | NEW |