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

Unified Diff: lib/src/stream_completer.dart

Issue 1615253002: Add ClosedStreamSink, and *Completer.setError, and StreamSinkCompleter.fromFuture. (Closed) Base URL: git@github.com:dart-lang/async.git@master
Patch Set: Created 4 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
Index: lib/src/stream_completer.dart
diff --git a/lib/src/stream_completer.dart b/lib/src/stream_completer.dart
index c343e6e7bd2330ccda59e9c793f96b0de3fbed50..0945b6a8733cae7d185cf5a436524e8c96b78dfa 100644
--- a/lib/src/stream_completer.dart
+++ b/lib/src/stream_completer.dart
@@ -39,9 +39,7 @@ class StreamCompleter<T> {
static Stream fromFuture(Future<Stream> streamFuture) {
var completer = new StreamCompleter();
streamFuture.then(completer.setSourceStream,
- onError: (e, s) {
- completer.setSourceStream(streamFuture.asStream());
- });
+ onError: completer.setError);
return completer.stream;
}
@@ -76,8 +74,8 @@ class StreamCompleter<T> {
/// it is immediately listened to, and its events are forwarded to the
/// existing subscription.
///
- /// Either [setSourceStream] or [setEmpty] may be called at most once.
- /// Trying to call either of them again will fail.
+ /// Any of [setSourceStream], [setEmpty], and [setError] may be called at most
Lasse Reichstein Nielsen 2016/01/22 09:13:47 Any one of ... (The current writing is unclear on
nweiz 2016/01/25 22:39:25 Done.
+ /// once. Trying to call any of them again will fail.
void setSourceStream(Stream<T> sourceStream) {
if (_stream._isSourceStreamSet) {
throw new StateError("Source stream already set");
@@ -87,14 +85,24 @@ class StreamCompleter<T> {
/// Equivalent to setting an empty stream using [setSourceStream].
///
- /// Either [setSourceStream] or [setEmpty] may be called at most once.
- /// Trying to call either of them again will fail.
+ /// Any of [setSourceStream], [setEmpty], and [setError] may be called at most
Lasse Reichstein Nielsen 2016/01/22 09:13:46 Any one of ...
nweiz 2016/01/25 22:39:25 Done.
+ /// once. Trying to call any of them again will fail.
void setEmpty() {
if (_stream._isSourceStreamSet) {
throw new StateError("Source stream already set");
}
_stream._setEmpty();
}
+
+ /// Completes this to a stream that emits [error] and then closes.
+ ///
+ /// This is useful when the process of loading the stream fails.
Lasse Reichstein Nielsen 2016/01/22 09:13:46 loading the stream -> creating the data for the st
nweiz 2016/01/25 22:39:25 Done.
+ ///
+ /// Any of [setSourceStream], [setEmpty], and [setError] may be called at most
Lasse Reichstein Nielsen 2016/01/22 09:13:46 Any one ..
nweiz 2016/01/25 22:39:25 Done.
+ /// once. Trying to call any of them again will fail.
+ void setError(error, [StackTrace stackTrace]) {
Lasse Reichstein Nielsen 2016/01/22 09:13:47 Good idea!
nweiz 2016/01/25 22:39:25 :D
+ setSourceStream(new Stream.fromFuture(new Future.error(error, stackTrace)));
+ }
}
/// Stream completed by [StreamCompleter].

Powered by Google App Engine
This is Rietveld 408576698