Files
sdk/tests/isolate/nested_spawn_stream_test.dart
T
floitsch@google.com 6c40cac7a9 Remove streamSpawnUri and mangler.
Add more tests.
Make dart2js send sinks.

Review URL: https://codereview.chromium.org//12919011

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@20213 260f80e4-7a28-3924-810f-c04153c831b5
2013-03-19 16:12:13 +00:00

62 lines
1.4 KiB
Dart

// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Dart test program for testing that isolates can spawn other isolates.
library NestedSpawnTest;
import 'dart:isolate';
import '../../pkg/unittest/lib/unittest.dart';
void isolateA() {
IsolateSink replyTo;
bool isFirst = true;
stream.listen((msg) {
if (isFirst) {
isFirst = false;
replyTo = msg;
return;
}
expect(msg, "launch nested!");
IsolateSink sink = streamSpawnFunction(isolateB);
MessageBox box = new MessageBox();
sink.add(box.sink);
sink.add("alive?");
box.stream.single.then((msg) {
expect(msg, "and kicking");
replyTo.add(499);
replyTo.close();
stream.close();
});
});
}
void isolateB() {
IsolateSink replyTo;
bool isFirst = true;
stream.listen((msg) {
if (isFirst) {
isFirst = false;
replyTo = msg;
return;
}
expect(msg, "alive?");
replyTo.add("and kicking");
replyTo.close();
stream.close();
});
}
main() {
test("spawned isolates can spawn nested isolates", () {
MessageBox box = new MessageBox();
IsolateSink sink = streamSpawnFunction(isolateA);
sink.add(box.sink);
sink.add("launch nested!");
box.stream.single.then(expectAsync1((msg) {
expect(msg, 499);
}));
});
}