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

Side by Side Diff: lib/stream_channel.dart

Issue 1610443002: Add StreamChannel and MultiChannel. (Closed) Base URL: git@github.com:dart-lang/stream_channel.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/src/multi_channel.dart ('k') | test/multi_channel_test.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 import 'dart:async';
6
7 export 'src/multi_channel.dart';
8
9 /// An abstract class representing a two-way communication channel.
10 ///
11 /// Subclasses are strongly encouraged to mix in or extend [StreamChannelMixin]
12 /// to get default implementations of the various instance methods. Adding new
13 /// methods to this interface will not be considered a breaking change if
14 /// implementations are also added to [StreamChannelMixin].
15 abstract class StreamChannel<T> {
16 /// The stream that emits values from the other endpoint.
17 Stream<T> get stream;
18
19 /// The sink for sending values to the other endpoint.
20 StreamSink<T> get sink;
21
22 /// Creates a new [StreamChannel] that communicates over [stream] and [sink].
23 factory StreamChannel(Stream<T> stream, StreamSink<T> sink) =>
24 new _StreamChannel<T>(stream, sink);
25
26 /// Connects [this] to [other], so that any values emitted by either are sent
27 /// directly to the other.
28 void pipe(StreamChannel<T> other);
29 }
30
31 /// An implementation of [StreamChannel] that simply takes a stream and a sink
32 /// as parameters.
33 ///
34 /// This is distinct from [StreamChannel] so that it can use
35 /// [StreamChannelMixin].
36 class _StreamChannel<T> extends StreamChannelMixin<T> {
37 final Stream<T> stream;
38 final StreamSink<T> sink;
39
40 _StreamChannel(this.stream, this.sink);
41 }
42
43 /// A mixin that implements the instance methods of [StreamChannel] in terms of
44 /// [stream] and [sink].
45 abstract class StreamChannelMixin<T> implements StreamChannel<T> {
46 void pipe(StreamChannel<T> other) {
47 stream.pipe(other.sink);
48 other.stream.pipe(sink);
49 }
50 }
OLDNEW
« no previous file with comments | « lib/src/multi_channel.dart ('k') | test/multi_channel_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698