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

Unified Diff: pkg/scheduled_test/lib/src/utils.dart

Issue 12741004: Accommodate a race condition in pkg/scheduled_test/scheduled_process_test. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove a bad timeout Created 7 years, 9 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 | « pkg/scheduled_test/lib/scheduled_process.dart ('k') | pkg/scheduled_test/test/scheduled_process_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/scheduled_test/lib/src/utils.dart
diff --git a/pkg/scheduled_test/lib/src/utils.dart b/pkg/scheduled_test/lib/src/utils.dart
index a832c8669a4a90a800b4d010fea7312f11004f12..898b72e31e0d6c0b4461b7476bb4136b72e1e788 100644
--- a/pkg/scheduled_test/lib/src/utils.dart
+++ b/pkg/scheduled_test/lib/src/utils.dart
@@ -104,16 +104,23 @@ Future streamFirst(Stream stream) {
return completer.future;
}
-/// Returns a wrapped version of [stream] along with a [StreamSubscription] that
-/// can be used to control the wrapped stream.
-Pair<Stream, StreamSubscription> streamWithSubscription(Stream stream) {
+/// A function that can be called to cancel a [Stream] and send a done message.
+typedef void StreamCanceller();
+
+// TODO(nweiz): use a StreamSubscription when issue 9026 is fixed.
+/// Returns a wrapped version of [stream] along with a function that will cancel
+/// the wrapped stream. Unlike [StreamSubscription], this canceller will send a
+/// "done" message to the wrapped stream.
+Pair<Stream, StreamCanceller> streamWithCanceller(Stream stream) {
var controller = stream.isBroadcast ?
new StreamController.broadcast() :
new StreamController();
- var subscription = stream.listen(controller.add,
- onError: controller.signalError,
- onDone: controller.close);
- return new Pair<Stream, StreamSubscription>(controller.stream, subscription);
+ var subscription = stream.listen((value) {
+ if (!controller.isClosed) controller.add(value);
+ }, onError: (error) {
+ if (!controller.isClosed) controller.signalError(error);
+ }, onDone: controller.close);
+ return new Pair<Stream, StreamCanceller>(controller.stream, controller.close);
}
// TODO(nweiz): remove this when issue 7787 is fixed.
« no previous file with comments | « pkg/scheduled_test/lib/scheduled_process.dart ('k') | pkg/scheduled_test/test/scheduled_process_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698