Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(281)

Side by Side Diff: tests/isolate/kill_self_test.dart

Issue 190013005: Add Isolate.kill(). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Changed naming and meaning of priorities Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 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 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:isolate"; 5 import "dart:isolate";
6 import "dart:async"; 6 import "dart:async";
7 import "package:expect/expect.dart"; 7 import "package:expect/expect.dart";
8 import "package:async_helper/async_helper.dart"; 8 import "package:async_helper/async_helper.dart";
9 9
10 isomain1(replyPort) { 10 isomain1(replyPort) {
11 RawReceivePort port = new RawReceivePort(); 11 RawReceivePort port = new RawReceivePort();
12 bool firstEvent = true;
12 port.handler = (v) { 13 port.handler = (v) {
13 replyPort.send(v); 14 if (!firstEvent) {
14 if (v == 0) port.close(); 15 throw "Survived suicide";
16 }
17 var controlPort = v[0];
18 var killCapability = v[1];
19 firstEvent = false;
20 var isolate = new Isolate(controlPort,
21 terminateCapability: killCapability);
22 isolate.kill(Isolate.ASAP);
15 }; 23 };
16 replyPort.send(port.sendPort); 24 replyPort.send(port.sendPort);
17 } 25 }
18 26
19 void main() { 27 void main() {
20 asyncStart(); 28 asyncStart();
21 var completer = new Completer(); // Completed by first reply from isolate. 29 var completer = new Completer(); // Completed by first reply from isolate.
22 RawReceivePort reply = new RawReceivePort(completer.complete); 30 RawReceivePort reply = new RawReceivePort(completer.complete);
23 Isolate.spawn(isomain1, reply.sendPort).then((Isolate isolate) { 31 Isolate.spawn(isomain1, reply.sendPort).then((Isolate isolate) {
24 List result = []; 32 completer.future.then((isolatePort) {
25 completer.future.then((echoPort) { 33 RawReceivePort exitSignal;
26 reply.handler = (v) { 34 exitSignal = new RawReceivePort((_) {
27 result.add(v); 35 exitSignal.close();
28 if (v == 0) { 36 asyncEnd();
29 Expect.listEquals([4, 3, 2, 1, 0], result); 37 });
30 reply.close(); 38 isolate.addOnExitListener(exitSignal.sendPort);
31 asyncEnd(); 39 isolatePort.send([isolate.controlPort, isolate.terminateCapability]);
32 } 40 reply.close();
33 };
34 echoPort.send(4);
35 echoPort.send(3);
36 Capability resume = isolate.pause();
37 var pingPort = new RawReceivePort();
38 pingPort.handler = (_) {
39 Expect.isTrue(result.length <= 2);
40 echoPort.send(0);
41 isolate.resume(resume);
42 pingPort.close();
43 };
44 isolate.ping(pingPort.sendPort, Isolate.PING_CONTROL);
45 echoPort.send(2);
46 echoPort.send(1);
47 }); 41 });
48 }); 42 });
49 } 43 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698