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

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

Issue 1074223002: Update Isolate API. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix typo Created 5 years, 8 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
« no previous file with comments | « tests/isolate/kill3_test.dart ('k') | tests/isolate/kill_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 bool firstEvent = true;
13 port.handler = (v) { 13 port.handler = (v) {
14 if (!firstEvent) { 14 if (!firstEvent) {
15 throw "Survived suicide"; 15 throw "Survived suicide";
16 } 16 }
17 var controlPort = v[0]; 17 var controlPort = v[0];
18 var killCapability = v[1]; 18 var killCapability = v[1];
19 firstEvent = false; 19 firstEvent = false;
20 var isolate = new Isolate(controlPort, 20 var isolate = new Isolate(controlPort,
21 terminateCapability: killCapability); 21 terminateCapability: killCapability);
22 isolate.kill(Isolate.IMMEDIATE); 22 isolate.kill(priority: Isolate.IMMEDIATE);
23 }; 23 };
24 replyPort.send(port.sendPort); 24 replyPort.send(port.sendPort);
25 } 25 }
26 26
27 void main() { 27 void main() {
28 asyncStart(); 28 asyncStart();
29 var completer = new Completer(); // Completed by first reply from isolate. 29 var completer = new Completer(); // Completed by first reply from isolate.
30 RawReceivePort reply = new RawReceivePort(completer.complete); 30 RawReceivePort reply = new RawReceivePort(completer.complete);
31 Isolate.spawn(isomain1, reply.sendPort).then((Isolate isolate) { 31 Isolate.spawn(isomain1, reply.sendPort).then((Isolate isolate) {
32 completer.future.then((isolatePort) { 32 completer.future.then((isolatePort) {
33 RawReceivePort exitSignal; 33 RawReceivePort exitSignal;
34 exitSignal = new RawReceivePort((_) { 34 exitSignal = new RawReceivePort((_) {
35 exitSignal.close(); 35 exitSignal.close();
36 asyncEnd(); 36 asyncEnd();
37 }); 37 });
38 isolate.addOnExitListener(exitSignal.sendPort); 38 isolate.addOnExitListener(exitSignal.sendPort);
39 isolatePort.send([isolate.controlPort, isolate.terminateCapability]); 39 isolatePort.send([isolate.controlPort, isolate.terminateCapability]);
40 reply.close(); 40 reply.close();
41 }); 41 });
42 }); 42 });
43 } 43 }
OLDNEW
« no previous file with comments | « tests/isolate/kill3_test.dart ('k') | tests/isolate/kill_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698