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

Unified Diff: lib/src/stream_channel_transformer.dart

Issue 2041983003: Add StreamChannel.withCloseGuarantee. (Closed) Base URL: git@github.com:dart-lang/stream_channel.git@master
Patch Set: Code review changes Created 4 years, 6 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/json_document_transformer.dart ('k') | lib/stream_channel.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/stream_channel_transformer.dart
diff --git a/lib/src/stream_channel_transformer.dart b/lib/src/stream_channel_transformer.dart
index ca09ea16bec34d6fb00dc0cd29f72848a7bb04ce..46232d74cc5df535ae22a844ac76d0fd97cd7f8f 100644
--- a/lib/src/stream_channel_transformer.dart
+++ b/lib/src/stream_channel_transformer.dart
@@ -17,7 +17,14 @@ import 'transformer/typed.dart';
/// [StreamSinkTransformer]. Each transformer defines a [bind] method that takes
/// in the original [StreamChannel] and returns the transformed version.
///
-/// Transformers must be able to have `bind` called multiple times.
+/// Transformers must be able to have [bind] called multiple times. If a
+/// subclass implements [bind] explicitly, it should be sure that the returned
+/// stream follows the second stream channel guarantee: closing the sink causes
+/// the stream to close before it emits any more events. This guarantee is
+/// invalidated when an asynchronous gap is added between the original stream's
+/// event dispatch and the returned stream's, for example by transforming it
+/// with a [StreamTransformer]. The guarantee can be easily preserved using [new
+/// StreamChannel.withCloseGuarantee].
class StreamChannelTransformer<S, T> {
/// The transformer to use on the channel's stream.
final StreamTransformer<T, S> _streamTransformer;
@@ -63,7 +70,7 @@ class StreamChannelTransformer<S, T> {
/// `channel.straem`, the transformer will transform them and pass the
/// transformed versions to the returned channel's stream.
StreamChannel<S> bind(StreamChannel<T> channel) =>
- new StreamChannel<S>(
+ new StreamChannel<S>.withCloseGuarantee(
channel.stream.transform(_streamTransformer),
_sinkTransformer.bind(channel.sink));
}
« no previous file with comments | « lib/src/json_document_transformer.dart ('k') | lib/stream_channel.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698