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

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

Issue 11864016: Support web workers in dart2js. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 11 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
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 library CountTest; 5 library CountTest;
6 import '../../pkg/unittest/lib/unittest.dart'; 6 import '../../pkg/unittest/lib/unittest.dart';
7 import 'dart:isolate'; 7 import 'dart:isolate';
8 8
9 void countMessages() { 9 void countMessages() {
10 int count = 0; 10 int count = 0;
(...skipping 12 matching lines...) Expand all
23 23
24 void main() { 24 void main() {
25 test("count 10 consecutive messages", () { 25 test("count 10 consecutive messages", () {
26 int count = 0; 26 int count = 0;
27 SendPort remote = spawnFunction(countMessages); 27 SendPort remote = spawnFunction(countMessages);
28 ReceivePort local = new ReceivePort(); 28 ReceivePort local = new ReceivePort();
29 SendPort reply = local.toSendPort(); 29 SendPort reply = local.toSendPort();
30 30
31 local.receive(expectAsync2((int message, SendPort replyTo) { 31 local.receive(expectAsync2((int message, SendPort replyTo) {
32 if (message == -1) { 32 if (message == -1) {
33 // [count] is '11' because when we sent '9' to [remote],
34 // the other isolate will send another message '18', that this
35 // isolate will receive. Then this isolate will send '10' to
36 // [remote] and increment [count]. Note that this last '10'
37 // message will not be received by the other isolate, since it
38 // received '-1' before.
33 expect(count, 11); 39 expect(count, 11);
34 local.close(); 40 local.close();
35 return; 41 return;
36 } 42 }
37 43
38 expect(message, (count - 1) * 2); 44 expect(message, (count - 1) * 2);
39 remote.send(count++, reply); 45 remote.send(count++, reply);
40 if (count == 10) { 46 if (count == 10) {
41 remote.send(-1, reply); 47 remote.send(-1, reply);
42 } 48 }
43 }, 11)); 49 }, 11));
44 remote.send(count++, reply); 50 remote.send(count++, reply);
45 }); 51 });
46 } 52 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698