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

Unified 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, 10 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 side-by-side diff with in-line comments
Download patch
« sdk/lib/isolate/isolate.dart ('K') | « sdk/lib/isolate/isolate.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/isolate/ondone_test.dart
diff --git a/tests/isolate/ondone_test.dart b/tests/isolate/ondone_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..c6e3b1e9eff628cbb37d83d37bf7cff81aab48ce
--- /dev/null
+++ b/tests/isolate/ondone_test.dart
@@ -0,0 +1,45 @@
+// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import "dart:isolate";
+import "dart:async";
+import "package:async_helper/async_helper.dart";
+
+void isomain(SendPort replyPort) {
+ RawReceivePort port = new RawReceivePort();
+ port.handler = (v) {
+ if (v == 0) {
+ // Shut down when receiving the 0 message.
+ port.close();
+ } else {
+ replyPort.send(v);
+ }
+ };
+ replyPort.send(port.sendPort);
+}
+
+void main() {
+ asyncStart();
+ var completer = new Completer(); // Completed by first reply from isolate.
+ RawReceivePort reply = new RawReceivePort(completer.complete);
+ bool mayComplete = false;
+ Isolate.spawn(isomain, reply.sendPort).then((Isolate isolate) {
+ isolate.onExit.then((_) {
+ reply.close();
+ if (!mayComplete) throw "COMPLETED EARLY";
+ asyncEnd();
+ });
+ return completer.future;
+ }).then((echoPort) {
+ int counter = 4;
+ reply.handler = (v) {
+ if (v != counter) throw "WRONG REPLY";
+ if (v == 0) throw "REPLY INSTEAD OF SHUTDOWN";
+ counter--;
+ mayComplete = (counter == 0);
+ echoPort.send(counter);
+ };
+ echoPort.send(counter);
+ });
+}
« 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