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

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

Issue 179823002: Add Isolate.onExit. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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
« sdk/lib/isolate/isolate.dart ('K') | « sdk/lib/isolate/isolate.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source 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 void isomain(SendPort replyPort) {
10 RawReceivePort port = new RawReceivePort();
11 port.handler = (v) {
12 if (v == 0) {
13 // Shut down when receiving the 0 message.
14 port.close();
15 } else {
16 replyPort.send(v);
17 }
18 };
19 replyPort.send(port.sendPort);
20 }
21
22 void main() {
23 asyncStart();
24 var completer = new Completer(); // Completed by first reply from isolate.
25 RawReceivePort reply = new RawReceivePort(completer.complete);
26 bool mayComplete = false;
27 Isolate.spawn(isomain, reply.sendPort).then((Isolate isolate) {
28 isolate.onExit.then((_) {
29 reply.close();
30 if (!mayComplete) throw "COMPLETED EARLY";
31 asyncEnd();
32 });
33 return completer.future;
34 }).then((echoPort) {
35 int counter = 4;
36 reply.handler = (v) {
37 if (v != counter) throw "WRONG REPLY";
38 if (v == 0) throw "REPLY INSTEAD OF SHUTDOWN";
39 counter--;
40 mayComplete = (counter == 0);
41 echoPort.send(counter);
42 };
43 echoPort.send(counter);
44 });
45 }
OLDNEW
« sdk/lib/isolate/isolate.dart ('K') | « sdk/lib/isolate/isolate.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698