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

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

Issue 153553009: Implement Isolate.pause in dart2js. (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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tests/isolate/isolate.status ('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
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:async_helper/async_helper.dart"; 7 import "package:async_helper/async_helper.dart";
8 8
9 isomain1(replyPort) { 9 isomain1(replyPort) {
10 RawReceivePort port = new RawReceivePort(); 10 RawReceivePort port = new RawReceivePort();
11 port.handler = (v) { 11 port.handler = (v) {
12 replyPort.send(v); 12 replyPort.send(v);
13 port.close(); 13 port.close();
14 }; 14 };
15 replyPort.send(port.sendPort); 15 replyPort.send(port.sendPort);
16 } 16 }
17 17
18 main(){ 18 main(){
19 asyncStart(); 19 asyncStart();
20 RawReceivePort reply = new RawReceivePort(); 20 RawReceivePort reply = new RawReceivePort();
21 Isolate isolate; 21 Isolate isolate;
22 Capability resume; 22 Capability resume;
23 var completer = new Completer(); // Completed by first reply from isolate. 23 var completer = new Completer(); // Completed by first reply from isolate.
24 reply.handler = completer.complete; 24 reply.handler = completer.complete;
25 Isolate.spawn(isomain1, reply.sendPort).then((Isolate iso) { 25 Isolate.spawn(isomain1, reply.sendPort).then((Isolate iso) {
26 isolate = iso; 26 isolate = iso;
27 resume = isolate.pause();
28 return completer.future; 27 return completer.future;
29 }).then((echoPort) { 28 }).then((echoPort) {
30 // Isolate has been created, and first response has been returned. 29 // Isolate has been created, and first response has been returned.
30 resume = isolate.pause();
31 echoPort.send(24); 31 echoPort.send(24);
32 reply.handler = (v) { 32 reply.handler = (v) {
33 throw "RESPONSE WHILE PAUSED?!?"; 33 throw "RESPONSE WHILE PAUSED?!?";
34 }; 34 };
35 return new Future.delayed(const Duration(milliseconds: 250)); 35 return new Future.delayed(const Duration(milliseconds: /*25*/0));
floitsch 2014/02/07 15:40:16 on purpose?
Lasse Reichstein Nielsen 2014/02/10 08:41:26 To make it run in d8 while testing. Will remove no
36 }).then((_) { 36 }).then((_) {
37 reply.handler = (v) { 37 reply.handler = (v) {
38 if (v != 24) throw "WRONG ANSWER!"; 38 if (v != 24) throw "WRONG ANSWER!";
39 print("Success");
floitsch 2014/02/07 15:40:16 debug?
Lasse Reichstein Nielsen 2014/02/10 08:41:26 Done.
39 reply.close(); 40 reply.close();
40 asyncEnd(); 41 asyncEnd();
41 }; 42 };
42 isolate.resume(resume); 43 isolate.resume(resume);
43 }); 44 });
44 } 45 }
OLDNEW
« no previous file with comments | « tests/isolate/isolate.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698