| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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("PromiseBasedTest"); | 5 #library("PromiseBasedTest"); |
| 6 #import("TestFramework.dart"); | 6 #import("TestFramework.dart"); |
| 7 | 7 |
| 8 class TestIsolate extends Isolate { | 8 class TestIsolate extends Isolate { |
| 9 | 9 |
| 10 TestIsolate() : super(); | 10 TestIsolate() : super(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 } | 26 } |
| 27 }); | 27 }); |
| 28 } | 28 } |
| 29 | 29 |
| 30 } | 30 } |
| 31 | 31 |
| 32 void test(TestExpectation expect) { | 32 void test(TestExpectation expect) { |
| 33 Proxy proxy = new Proxy.forIsolate(new TestIsolate()); | 33 Proxy proxy = new Proxy.forIsolate(new TestIsolate()); |
| 34 proxy.send([42]); // Seed the isolate. | 34 proxy.send([42]); // Seed the isolate. |
| 35 Promise<int> result = new PromiseProxy<int>(proxy.call([87])); | 35 Promise<int> result = new PromiseProxy<int>(proxy.call([87])); |
| 36 Promise promise = expect.completes(result).then((int value) { | 36 Completer completer = new Completer(); |
| 37 expect.completes(result).then((int value) { |
| 37 //print("expect 1: $value"); | 38 //print("expect 1: $value"); |
| 38 Expect.equals(42 + 87, value); | 39 Expect.equals(42 + 87, value); |
| 39 return 99; | 40 completer.complete(99); |
| 40 }); | 41 }); |
| 41 expect.completes(promise).then((int value) { | 42 expect.completes(completer.future).then((int value) { |
| 42 //print("expect 2: $value"); | 43 //print("expect 2: $value"); |
| 43 Expect.equals(99, value); | 44 Expect.equals(99, value); |
| 44 expect.succeeded(); | 45 expect.succeeded(); |
| 45 }); | 46 }); |
| 46 } | 47 } |
| 47 | 48 |
| 48 void expandedTest(TestExpectation expect) { | 49 void expandedTest(TestExpectation expect) { |
| 49 Proxy proxy = new Proxy.forIsolate(new TestIsolate()); | 50 Proxy proxy = new Proxy.forIsolate(new TestIsolate()); |
| 50 proxy.send([42]); // Seed the isolate. | 51 proxy.send([42]); // Seed the isolate. |
| 51 Promise<SendPort> sendCompleter = proxy.call([87]); | 52 Promise<SendPort> sendCompleter = proxy.call([87]); |
| 52 Promise<int> result = new Promise<int>(); | 53 Promise<int> result = new Promise<int>(); |
| 53 ReceivePort completer = new ReceivePort.singleShot(); | 54 ReceivePort receivePort = new ReceivePort.singleShot(); |
| 54 completer.receive((var msg, SendPort _) { | 55 receivePort.receive((var msg, SendPort _) { |
| 55 //print("test completer"); | 56 //print("test completer"); |
| 56 result.complete(msg[0]); | 57 result.complete(msg[0]); |
| 57 }); | 58 }); |
| 58 sendCompleter.addCompleteHandler((SendPort port) { | 59 sendCompleter.addCompleteHandler((SendPort port) { |
| 59 //print("test send"); | 60 //print("test send"); |
| 60 port.send([completer.toSendPort()], null); | 61 port.send([receivePort.toSendPort()], null); |
| 61 }); | 62 }); |
| 62 Promise promise = expect.completes(result).then((int value) { | 63 Completer completer = new Completer(); |
| 64 expect.completes(result).then((int value) { |
| 63 //print("expect 1: $value"); | 65 //print("expect 1: $value"); |
| 64 Expect.equals(42 + 87, value); | 66 Expect.equals(42 + 87, value); |
| 65 return 99; | 67 completer.complete(99); |
| 66 }); | 68 }); |
| 67 expect.completes(promise).then((int value) { | 69 expect.completes(completer.future).then((int value) { |
| 68 //print("expect 2: $value"); | 70 //print("expect 2: $value"); |
| 69 Expect.equals(99, value); | 71 Expect.equals(99, value); |
| 70 expect.succeeded(); | 72 expect.succeeded(); |
| 71 }); | 73 }); |
| 72 } | 74 } |
| 73 | 75 |
| 74 void main() { | 76 void main() { |
| 75 runTests([test, expandedTest]); | 77 runTests([test, expandedTest]); |
| 76 } | 78 } |
| OLD | NEW |