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

Side by Side Diff: lib/src/util/stream_channel.dart

Issue 1664433002: Support shelf 0.7.0. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Code review changes Created 4 years, 10 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/util/multi_channel.dart ('k') | lib/src/utils.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) 2015, 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 /// An abstract class representing a two-way communication channel.
8 ///
9 /// Subclasses can mix in [StreamChannelMixin] to get default implementations of
10 /// the various instance methods.
11 abstract class StreamChannel<T> {
12 /// The stream that emits values from the other endpoint.
13 Stream<T> get stream;
14
15 /// The sink for sending values to the other endpoint.
16 StreamSink<T> get sink;
17
18 /// Creates a new [StreamChannel] that communicates over [stream] and [sink].
19 factory StreamChannel(Stream<T> stream, StreamSink<T> sink) =>
20 new _StreamChannel<T>(stream, sink);
21
22 /// Connects [this] to [other], so that any values emitted by either are sent
23 /// directly to the other.
24 void pipe(StreamChannel<T> other);
25 }
26
27 /// An implementation of [StreamChannel] that simply takes a stream and a sink
28 /// as parameters.
29 ///
30 /// This is distinct from [StreamChannel] so that it can use
31 /// [StreamChannelMixin].
32 class _StreamChannel<T> extends StreamChannelMixin<T> {
33 final Stream<T> stream;
34 final StreamSink<T> sink;
35
36 _StreamChannel(this.stream, this.sink);
37 }
38
39 /// A mixin that implements the instance methods of [StreamChannel] in terms of
40 /// [stream] and [sink].
41 abstract class StreamChannelMixin<T> implements StreamChannel<T> {
42 void pipe(StreamChannel<T> other) {
43 stream.pipe(other.sink);
44 other.stream.pipe(sink);
45 }
46 }
OLDNEW
« no previous file with comments | « lib/src/util/multi_channel.dart ('k') | lib/src/utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698