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

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

Issue 12330062: Add a filesystem descriptor library to scheduled_test. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 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
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 b5e086e4c11b38c34d64e255f8fe590bf28d004a..03039e451717c88965bba7a3af507561b72e63e0 100644
--- a/pkg/scheduled_test/lib/src/utils.dart
+++ b/pkg/scheduled_test/lib/src/utils.dart
@@ -24,3 +24,38 @@ Future pumpEventQueue([int times=200]) {
if (times == 0) return new Future.immediate(null);
return new Future.immediate(null).then((_) => pumpEventQueue(times - 1));
}
+
+/// Returns whether [iterable1] has the same elements in the same order as
+/// [iterable2]. The elements are compared using `==`.
+bool orderedIterableEquals(Iterable iterable1, Iterable iterable2) {
+ var iter1 = iterable1.iterator;
+ var iter2 = iterable2.iterator;
+
+ while (true) {
+ if (iter1.current != iter2.current) return false;
Bob Nystrom 2013/02/22 17:58:21 The iterator protocol says you need to call moveNe
nweiz 2013/02/22 20:57:20 Done.
+ var hasNext1 = iter1.moveNext();
+ var hasNext2 = iter2.moveNext();
+ if (hasNext1 != hasNext2) return false;
+ if (!hasNext1) return true;
+ }
+}
+
+/// Returns a [Stream] that will immediately emit [error] and then close.
Bob Nystrom 2013/02/22 17:58:21 Given corelib has Future.immediateError, I wonder
nweiz 2013/02/22 20:57:20 Done.
+Stream errorStream(error) => new Future.immediateError(error).asStream();
+
+/// Returns a buffered stream that will emit the same values as the stream
+/// returned by [future] once [future] completes. If [future] completes to an
+/// error, the return value will emit that error and then close.
+Stream liftStream(Future<Stream> future) {
Bob Nystrom 2013/02/22 17:58:21 Instead of "lift", how about "deferred" or just "f
nweiz 2013/02/22 20:57:20 Done.
+ var controller = new StreamController();
+ future.then((stream) {
+ stream.listen(
+ controller.add,
+ onError: (error) => controller.signalError(error),
+ onDone: controller.close);
+ }).catchError((e) {
+ controller.signalError(e);
+ controller.close();
+ });
+ return controller.stream;
+}

Powered by Google App Engine
This is Rietveld 408576698