Skip to content

Commit 5265a85

Browse files
authored
Merge pull request #1957 from dart-lang/stream-channel-mixin
make StreamChannelMixin an abstract mixin class
2 parents b412ba4 + 9ea86c9 commit 5265a85

File tree

4 files changed

+48
-2
lines changed

4 files changed

+48
-2
lines changed

pkgs/stream_channel/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.1.4
2+
3+
* Fix `StreamChannelMixin` so that it can be used as a mixin again.
4+
15
## 2.1.3
26

37
* Require Dart 3.3

pkgs/stream_channel/lib/stream_channel.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ class _StreamChannel<T> extends StreamChannelMixin<T> {
148148

149149
/// A mixin that implements the instance methods of [StreamChannel] in terms of
150150
/// [stream] and [sink].
151-
abstract class StreamChannelMixin<T> implements StreamChannel<T> {
151+
abstract mixin class StreamChannelMixin<T> implements StreamChannel<T> {
152152
@override
153153
void pipe(StreamChannel<T> other) {
154154
stream.pipe(other.sink);

pkgs/stream_channel/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: stream_channel
2-
version: 2.1.3
2+
version: 2.1.4
33
description: >-
44
An abstraction for two-way communication channels based on the Dart Stream
55
class.

pkgs/stream_channel/test/stream_channel_test.dart

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,46 @@ void main() {
135135
changed.sink.add(10);
136136
changed.sink.close();
137137
});
138+
139+
group('StreamChannelMixin', () {
140+
test('can be used as a mixin', () async {
141+
var channel = StreamChannelMixinAsMixin<int>();
142+
expect(channel.stream, emitsInOrder([1, 2, 3]));
143+
channel.sink
144+
..add(1)
145+
..add(2)
146+
..add(3);
147+
await channel.controller.close();
148+
});
149+
150+
test('can be extended', () async {
151+
var channel = StreamChannelMixinAsSuperclass<int>();
152+
expect(channel.stream, emitsInOrder([1, 2, 3]));
153+
channel.sink
154+
..add(1)
155+
..add(2)
156+
..add(3);
157+
await channel.controller.close();
158+
});
159+
});
160+
}
161+
162+
class StreamChannelMixinAsMixin<T> with StreamChannelMixin<T> {
163+
final controller = StreamController<T>();
164+
165+
@override
166+
StreamSink<T> get sink => controller.sink;
167+
168+
@override
169+
Stream<T> get stream => controller.stream;
170+
}
171+
172+
class StreamChannelMixinAsSuperclass<T> extends StreamChannelMixin<T> {
173+
final controller = StreamController<T>();
174+
175+
@override
176+
StreamSink<T> get sink => controller.sink;
177+
178+
@override
179+
Stream<T> get stream => controller.stream;
138180
}

0 commit comments

Comments
 (0)