Skip to content

Commit

Permalink
make StreamChannelMixin an abstract mixin class
Browse files Browse the repository at this point in the history
  • Loading branch information
jakemac53 committed Jan 6, 2025
1 parent b412ba4 commit 9ea86c9
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
4 changes: 4 additions & 0 deletions pkgs/stream_channel/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.1.4

* Fix `StreamChannelMixin` so that it can be used as a mixin again.

## 2.1.3

* Require Dart 3.3
Expand Down
2 changes: 1 addition & 1 deletion pkgs/stream_channel/lib/stream_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class _StreamChannel<T> extends StreamChannelMixin<T> {

/// A mixin that implements the instance methods of [StreamChannel] in terms of
/// [stream] and [sink].
abstract class StreamChannelMixin<T> implements StreamChannel<T> {
abstract mixin class StreamChannelMixin<T> implements StreamChannel<T> {
@override
void pipe(StreamChannel<T> other) {
stream.pipe(other.sink);
Expand Down
2 changes: 1 addition & 1 deletion pkgs/stream_channel/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: stream_channel
version: 2.1.3
version: 2.1.4
description: >-
An abstraction for two-way communication channels based on the Dart Stream
class.
Expand Down
42 changes: 42 additions & 0 deletions pkgs/stream_channel/test/stream_channel_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,46 @@ void main() {
changed.sink.add(10);
changed.sink.close();
});

group('StreamChannelMixin', () {
test('can be used as a mixin', () async {
var channel = StreamChannelMixinAsMixin<int>();
expect(channel.stream, emitsInOrder([1, 2, 3]));
channel.sink
..add(1)
..add(2)
..add(3);
await channel.controller.close();
});

test('can be extended', () async {
var channel = StreamChannelMixinAsSuperclass<int>();
expect(channel.stream, emitsInOrder([1, 2, 3]));
channel.sink
..add(1)
..add(2)
..add(3);
await channel.controller.close();
});
});
}

class StreamChannelMixinAsMixin<T> with StreamChannelMixin<T> {
final controller = StreamController<T>();

@override
StreamSink<T> get sink => controller.sink;

@override
Stream<T> get stream => controller.stream;
}

class StreamChannelMixinAsSuperclass<T> extends StreamChannelMixin<T> {
final controller = StreamController<T>();

@override
StreamSink<T> get sink => controller.sink;

@override
Stream<T> get stream => controller.stream;
}

0 comments on commit 9ea86c9

Please sign in to comment.