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

Unified Diff: tests/html/isolates_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/html/async_test.dart ('k') | tests/html/worker_api_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/html/isolates_test.dart
diff --git a/tests/html/isolates_test.dart b/tests/html/isolates_test.dart
index 1320d226dd0d1c14794be10871f54fd8a9f280a8..fe35c20904e1bd5535f5e119fb8227056f0b4d77 100644
--- a/tests/html/isolates_test.dart
+++ b/tests/html/isolates_test.dart
@@ -7,7 +7,10 @@ import 'dart:isolate' as isolate;
String responseFor(message) => 'response for $message';
-void isolateEntry() {
+void isolateEntry(isolate.SendPort initialReplyTo) {
+ var port = new isolate.ReceivePort();
+ initialReplyTo.send(port.sendPort);
+
bool wasThrown = false;
try {
window.alert('Test');
@@ -22,28 +25,41 @@ void isolateEntry() {
// Check that convert library was loaded to isolate.
JSON.encode([1, 2, 3]);
- isolate.port.receive((message, replyTo) {
- replyTo.send(responseFor(message), null);
+ port.listen((message) {
+ var data = message[0];
+ var replyTo = message[1];
+ replyTo.send(responseFor(data));
});
}
+Future sendReceive(isolate.SendPort port, msg) {
+ var response = new isolate.ReceivePort();
+ port.send([msg, response.sendPort]);
+ return response.first;
+}
+
main() {
useHtmlConfiguration();
test('IsolateSpawn', () {
- isolate.spawnFunction(isolateEntry);
+ var port = new isolate.ReceivePort();
+ isolate.Isolate.spawn(isolateEntry, port.sendPort);
+ port.close();
});
test('NonDOMIsolates', () {
var callback = expectAsync0((){});
- var port = isolate.spawnFunction(isolateEntry);
- final msg1 = 'foo';
- final msg2 = 'bar';
- port.call(msg1).then((response) {
- guardAsync(() {
- expect(response, equals(responseFor(msg1)));
- port.call(msg2).then((response) {
- guardAsync(() {
- expect(response, equals(responseFor(msg2)));
- callback();
+ var response = new isolate.ReceivePort();
+ var remote = isolate.Isolate.spawn(isolateEntry, response.sendPort);
+ response.first.then((port) {
+ final msg1 = 'foo';
+ final msg2 = 'bar';
+ sendReceive(port, msg1).then((response) {
+ guardAsync(() {
+ expect(response, equals(responseFor(msg1)));
+ sendReceive(port, msg2).then((response) {
+ guardAsync(() {
+ expect(response, equals(responseFor(msg2)));
+ callback();
+ });
});
});
});
« no previous file with comments | « tests/html/async_test.dart ('k') | tests/html/worker_api_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698