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

Unified Diff: pkg/barback/lib/src/stream_replayer.dart

Issue 119673002: Add a ScheduledStream class and some stream matchers. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review Created 6 years, 11 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 | « no previous file | pkg/barback/lib/src/utils.dart » ('j') | pkg/barback/lib/src/utils.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/barback/lib/src/stream_replayer.dart
diff --git a/pkg/barback/lib/src/stream_replayer.dart b/pkg/barback/lib/src/stream_replayer.dart
index 705f97aec14cd7b31fecd310d101f565fdaab45a..6289a6219a3b36aa688c68a35aa7df3414efcfc5 100644
--- a/pkg/barback/lib/src/stream_replayer.dart
+++ b/pkg/barback/lib/src/stream_replayer.dart
@@ -27,9 +27,9 @@ class StreamReplayer<T> {
/// The buffer of events or errors that have already been emitted by
/// [_stream].
///
- /// Each element is a [Either] that's either a value or an error sent through
- /// the stream.
- final _buffer = new Queue<Either<T, Pair<dynamic, StackTrace>>>();
+ /// Each element is a [FallibleValue] that's either a value or an error sent
+ /// through the stream.
+ final _buffer = new Queue<FallibleValue<T>>();
/// The controllers that are listening for future events from [_stream].
final _controllers = new Set<StreamController<T>>();
@@ -43,9 +43,11 @@ class StreamReplayer<T> {
var controller = new StreamController<T>(onListen: _subscribe);
for (var eventOrError in _buffer) {
- eventOrError.match(controller.add, (pair) {
- controller.addError(pair.first, pair.second);
- });
+ if (eventOrError.hasValue) {
+ controller.add(eventOrError.value);
+ } else {
+ controller.addError(eventOrError.error, eventOrError.stackTrace);
+ }
}
if (_isClosed) {
controller.close();
@@ -61,13 +63,12 @@ class StreamReplayer<T> {
_isSubscribed = true;
_stream.listen((data) {
- _buffer.add(new Either<T, dynamic>.withFirst(data));
+ _buffer.add(new FallibleValue<T>.withValue(data));
for (var controller in _controllers) {
controller.add(data);
}
}, onError: (error, [stackTrace]) {
- _buffer.add(new Either<T, Pair<dynamic, StackTrace>>.withSecond(
- new Pair<dynamic, StackTrace>(error, stackTrace)));
+ _buffer.add(new FallibleValue<T>.withError(error, stackTrace));
for (var controller in _controllers) {
controller.addError(error, stackTrace);
}
« no previous file with comments | « no previous file | pkg/barback/lib/src/utils.dart » ('j') | pkg/barback/lib/src/utils.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698