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

Unified Diff: tests/isolate/unresolved_ports_test.dart

Issue 27215002: Very simple version of Isolates. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 7 years, 2 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
« no previous file with comments | « tests/isolate/stream_mangling_test.dart ('k') | tests/language/typed_message_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/isolate/unresolved_ports_test.dart
diff --git a/tests/isolate/unresolved_ports_test.dart b/tests/isolate/unresolved_ports_test.dart
index 107200030ff41d2f70e63d51001fb898f5aab2b3..00cf144e0ac0a65bc7c65cfe7f28fff11445c06f 100644
--- a/tests/isolate/unresolved_ports_test.dart
+++ b/tests/isolate/unresolved_ports_test.dart
@@ -14,28 +14,45 @@ import '../../pkg/unittest/lib/unittest.dart';
// main -> beth -> tim -> bob -> main
// by giving 'beth' a send-port to 'tim'.
-bethIsolate() {
+bethIsolate(init) {
+ ReceivePort port = initIsolate(init);
// TODO(sigmund): use expectAsync2 when it is OK to use it within an isolate
// (issue #6856)
- port.receive((msg, reply) => msg[1].send(
- '${msg[0]}\nBeth says: Tim are you coming? And Bob?', reply));
+ port.first.then((msg) => msg[1].send([
+ '${msg[0]}\nBeth says: Tim are you coming? And Bob?', msg[2]]));
}
-timIsolate() {
- SendPort bob = spawnFunction(bobIsolate);
- port.receive((msg, reply) => bob.send(
- '$msg\nTim says: Can you tell "main" that we are all coming?', reply));
+timIsolate(init) {
+ ReceivePort port = initIsolate(init);
+ spawnFunction(bobIsolate).then((bob) {
+ port.first.then((msg) => bob.send([
+ '${msg[0]}\nTim says: Can you tell "main" that we are all coming?',
+ msg[1]]));
+ });
+}
+
+bobIsolate(init) {
+ ReceivePort port = initIsolate(init);
+ port.first.then((msg) => msg[1].send(
+ '${msg[0]}\nBob says: we are all coming!'));
+}
+
+Future<SendPort> spawnFunction(function) {
+ ReceivePort init = new ReceivePort();
+ Isolate.spawn(function, init.sendPort);
+ return init.first;
}
-bobIsolate() {
- port.receive((msg, reply) => reply.send(
- '$msg\nBob says: we are all coming!'));
+ReceivePort initIsolate(SendPort starter) {
+ ReceivePort port = new ReceivePort();
+ starter.send(port.sendPort);
+ return port;
}
baseTest({bool failForNegativeTest: false}) {
test('Message chain with unresolved ports', () {
ReceivePort port = new ReceivePort();
- port.receive(expectAsync2((msg, _) {
+ port.listen(expectAsync1((msg) {
expect(msg, equals('main says: Beth, find out if Tim is coming.'
'\nBeth says: Tim are you coming? And Bob?'
'\nTim says: Can you tell "main" that we are all coming?'
@@ -44,14 +61,13 @@ baseTest({bool failForNegativeTest: false}) {
port.close();
}));
- SendPort tim = spawnFunction(timIsolate);
- SendPort beth = spawnFunction(bethIsolate);
+ spawnFunction(timIsolate).then((tim) {
+ spawnFunction(bethIsolate).then((beth) {
+ beth.send(['main says: Beth, find out if Tim is coming.',
+ tim, port.sendPort]);
+ });
+ });
- beth.send(
- // because tim is created asynchronously, here we are sending an
- // unresolved port:
- ['main says: Beth, find out if Tim is coming.', tim],
- port.toSendPort());
});
}
« no previous file with comments | « tests/isolate/stream_mangling_test.dart ('k') | tests/language/typed_message_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698