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

Side by Side Diff: lib/src/stream_sink_transformer.dart

Issue 1566603002: Add a StreamSinkTransformer class. (Closed) Base URL: git@github.com:dart-lang/async.git@master
Patch Set: Code review changes 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 unified diff | Download patch
« no previous file with comments | « lib/async.dart ('k') | lib/src/stream_sink_transformer/handler_transformer.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 library async.stream_sink_transformer;
6
7 import 'dart:async';
8
9 import 'stream_sink_transformer/handler_transformer.dart';
10 import 'stream_sink_transformer/stream_transformer_wrapper.dart';
11
12 /// A [StreamSinkTransformer] transforms the events being passed to a sink.
13 ///
14 /// This works on the same principle as a [StreamTransformer]. Each transformer
15 /// defines a [bind] method that takes in the original [StreamSink] and returns
16 /// the transformed version. However, where a [StreamTransformer] transforms
17 /// events after they leave the stream, this transforms them before they enter
18 /// the sink.
19 ///
20 /// Transformers must be able to have `bind` called used multiple times.
21 abstract class StreamSinkTransformer<S, T> {
22 /// Creates a [StreamSinkTransformer] that transforms events and errors
23 /// using [transformer].
24 ///
25 /// This is equivalent to piping all events from the outer sink through a
26 /// stream transformed by [transformer] and from there into the inner sink.
27 const factory StreamSinkTransformer.fromStreamTransformer(
28 StreamTransformer<S, T> transformer) =
29 StreamTransformerWrapper<S, T>;
30
31 /// Creates a [StreamSinkTransformer] that delegates events to the given
32 /// handlers.
33 ///
34 /// The handlers work exactly as they do for [StreamTransformer.fromHandlers].
35 /// They're called for each incoming event, and any actions on the sink
36 /// they're passed are forwarded to the inner sink. If a handler is omitted,
37 /// the event is passed through unaltered.
38 factory StreamSinkTransformer.fromHandlers({
39 void handleData(S data, EventSink<T> sink),
40 void handleError(Object error, StackTrace stackTrace, EventSink<T> sink),
41 void handleDone(EventSink<T> sink)}) {
42 return new HandlerTransformer<S, T>(handleData, handleError, handleDone);
43 }
44
45 /// Transforms the events passed to [sink].
46 ///
47 /// Creates a new sink. When events are passed to the returned sink, it will
48 /// transform them and pass the transformed versions to [sink].
49 StreamSink<S> bind(StreamSink<T> sink);
50 }
OLDNEW
« no previous file with comments | « lib/async.dart ('k') | lib/src/stream_sink_transformer/handler_transformer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698