OLD | NEW |
---|---|
(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 library async.delegate.stream_controller; | |
6 | |
7 import 'dart:async'; | |
8 | |
9 import 'stream_sink.dart'; | |
10 | |
11 /// Simple delegating wrapper around an [StreamController]. | |
Lasse Reichstein Nielsen
2015/07/02 09:38:39
I'm not sure I'd consider StreamController an inte
nweiz
2015/07/06 20:40:30
I don't think of this as a way for otherwise non-c
Lasse Reichstein Nielsen
2015/07/07 10:32:18
I'm not sure I would encourage an extended StreamC
nweiz
2015/07/07 21:51:59
I think there's documentary value in sharing an in
| |
12 /// | |
13 /// Subclasses can override individual methods, or use this to expose only the | |
14 /// [StreamController] methods of a subclass. | |
15 /// | |
16 /// Note that [sink] will provide a sink view of the delegating controller, | |
17 /// rather than of the underlying controller. | |
18 class DelegatingStreamController<T> implements StreamController<T> { | |
19 final StreamController _controller; | |
20 | |
21 Future get done => _controller.done; | |
22 | |
23 bool get hasListener => _controller.hasListener; | |
24 | |
25 bool get isClosed => _controller.isClosed; | |
26 | |
27 bool get isPaused => _controller.isPaused; | |
28 | |
29 StreamSink<T> get sink => new DelegatingStreamSink<T>(this); | |
30 | |
31 Stream<T> get stream => _controller.stream; | |
32 | |
33 /// Create a delegating controller forwarding calls to [controller]. | |
34 DelegatingStreamController(StreamController controller) | |
35 : _controller = controller; | |
36 | |
37 void add(T data) => _controller.add(data); | |
38 | |
39 void addError(error, [StackTrace stackTrace]) => | |
40 _controller.addError(error, stackTrace); | |
41 | |
42 Future addStream(Stream<T> stream, {bool cancelOnError: true}) => | |
43 _controller.addStream(stream, cancelOnError: cancelOnError); | |
44 | |
45 Future close() => _controller.close(); | |
46 } | |
OLD | NEW |