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

Side by Side Diff: tests/isolate/kill2_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 | « sdk/lib/isolate/isolate.dart ('k') | tests/isolate/kill3_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 port.handler = (v) { 12 port.handler = (v) {
13 replyPort.send(v); 13 replyPort.send(v);
14 if (v == 0) port.close(); 14 if (v == 0) port.close();
15 }; 15 };
16 replyPort.send(port.sendPort); 16 replyPort.send(port.sendPort);
17 } 17 }
18 18
19 void main() { 19 void main() {
20 asyncStart(); 20 asyncStart();
21 var completer = new Completer(); // Completed by first reply from isolate. 21 var completer = new Completer(); // Completed by first reply from isolate.
22 RawReceivePort reply = new RawReceivePort(completer.complete); 22 RawReceivePort reply = new RawReceivePort(completer.complete);
23 Isolate.spawn(isomain1, reply.sendPort).then((Isolate isolate) { 23 Isolate.spawn(isomain1, reply.sendPort).then((Isolate isolate) {
24 List result = []; 24 List result = [];
25 completer.future.then((echoPort) { 25 completer.future.then((echoPort) {
26 reply.handler = (v) { 26 reply.handler = (v) {
27 result.add(v); 27 result.add(v);
28 if (v == 2) { 28 if (v == 2) {
29 isolate.kill(Isolate.BEFORE_NEXT_EVENT); 29 isolate.kill(priority: Isolate.BEFORE_NEXT_EVENT);
30 } 30 }
31 echoPort.send(v - 1); 31 echoPort.send(v - 1);
32 }; 32 };
33 RawReceivePort exitSignal; 33 RawReceivePort exitSignal;
34 exitSignal = new RawReceivePort((_) { 34 exitSignal = new RawReceivePort((_) {
35 Expect.listEquals([4, 3, 2], result); 35 Expect.listEquals([4, 3, 2], result);
36 exitSignal.close(); 36 exitSignal.close();
37 reply.close(); 37 reply.close();
38 asyncEnd(); 38 asyncEnd();
39 }); 39 });
40 isolate.addOnExitListener(exitSignal.sendPort); 40 isolate.addOnExitListener(exitSignal.sendPort);
41 echoPort.send(4); 41 echoPort.send(4);
42 }); 42 });
43 }); 43 });
44 } 44 }
OLDNEW
« no previous file with comments | « sdk/lib/isolate/isolate.dart ('k') | tests/isolate/kill3_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698