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

Unified Diff: lib/src/utils.dart

Issue 1056733002: Run test tearDowns and clean up temporary directories when a signal is caught. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Code review changes Created 5 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 | « lib/src/util/io.dart ('k') | pubspec.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/utils.dart
diff --git a/lib/src/utils.dart b/lib/src/utils.dart
index 97997d7752521a1e30d13ec6997ad4e04f4a19d2..7d1094edd970080d7e04b8690353efb78633cad2 100644
--- a/lib/src/utils.dart
+++ b/lib/src/utils.dart
@@ -16,6 +16,9 @@ import 'backend/operating_system.dart';
/// The return type should only ever by [Future] or void.
typedef AsyncFunction();
+/// A typedef for a zero-argument callback function.
+typedef void Callback();
+
/// A regular expression to match the exception prefix that some exceptions'
/// [Object.toString] values contain.
final _exceptionPrefix = new RegExp(r'^([A-Z][a-zA-Z]*)?(Exception|Error): ');
@@ -141,3 +144,38 @@ String truncate(String text, int maxLength) {
}
return '...$result';
}
+
+/// Merges [streams] into a single stream that emits events from all sources.
+Stream mergeStreams(Iterable<Stream> streamIter) {
+ var streams = streamIter.toList();
+
+ var subscriptions = new Set();
+ var controller;
+ controller = new StreamController(sync: true, onListen: () {
+ for (var stream in streams) {
+ var subscription;
+ subscription = stream.listen(
+ controller.add,
+ onError: controller.addError,
+ onDone: () {
+ subscriptions.remove(subscription);
+ if (subscriptions.isEmpty) controller.close();
+ });
+ subscriptions.add(subscription);
+ }
+ }, onPause: () {
+ for (var subscription in subscriptions) {
+ subscription.pause();
+ }
+ }, onResume: () {
+ for (var subscription in subscriptions) {
+ subscription.resume();
+ }
+ }, onCancel: () {
+ for (var subscription in subscriptions) {
+ subscription.cancel();
+ }
+ });
+
+ return controller.stream;
+}
« no previous file with comments | « lib/src/util/io.dart ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698