Skip to content

Commit

Permalink
Require Dart 3.3, update and fix lints (dart-lang/stream_channel#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevmoo authored Feb 17, 2024
1 parent c7eef23 commit 45fbe10
Show file tree
Hide file tree
Showing 16 changed files with 71 additions and 50 deletions.
2 changes: 1 addition & 1 deletion pkgs/stream_channel/.github/workflows/test-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
matrix:
# Add macos-latest and/or windows-latest if relevant for this package.
os: [ubuntu-latest]
sdk: [2.19.0, dev]
sdk: [3.3, dev]
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3
Expand Down
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.3-wip

* Require Dart 3.3

## 2.1.2

* Require Dart 2.19
Expand Down
6 changes: 3 additions & 3 deletions pkgs/stream_channel/example/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Future<void> main() async {
// For example, we can handle standard input as strings:
var stringChannel = stdioChannel
.transform(StreamChannelTransformer.fromCodec(utf8))
.transformStream(LineSplitter());
.transformStream(const LineSplitter());
stringChannel.sink.add('world!\n');

// You can implement StreamChannel<T> by extending StreamChannelMixin<T>, but
Expand Down Expand Up @@ -84,8 +84,8 @@ Future<void> main() async {
// given the corresponding `SendPort`, and then call
// `IsolateChannel.connectSend`.
var recv = ReceivePort();
var recvChannel = IsolateChannel.connectReceive(recv);
var sendChannel = IsolateChannel.connectSend(recv.sendPort);
var recvChannel = IsolateChannel<void>.connectReceive(recv);
var sendChannel = IsolateChannel<void>.connectSend(recv.sendPort);

// You must manually close `IsolateChannel<T>` sinks, however.
await recvChannel.sink.close();
Expand Down
2 changes: 1 addition & 1 deletion pkgs/stream_channel/lib/src/disconnector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Disconnector<T> implements StreamChannelTransformer<T, T> {
_sinks.clear();
return Future.wait(futures, eagerError: true);
});
final _disconnectMemo = AsyncMemoizer();
final _disconnectMemo = AsyncMemoizer<List<void>>();

@override
StreamChannel<T> bind(StreamChannel<T> channel) {
Expand Down
2 changes: 1 addition & 1 deletion pkgs/stream_channel/lib/src/guarantee_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class _GuaranteeSink<T> implements StreamSink<T> {

@override
Future<void> get done => _doneCompleter.future;
final _doneCompleter = Completer();
final _doneCompleter = Completer<void>();

/// Whether connection is disconnected.
///
Expand Down
2 changes: 1 addition & 1 deletion pkgs/stream_channel/lib/src/isolate_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class IsolateChannel<T> extends StreamChannelMixin<T> {
.transform(StreamSinkTransformer.fromHandlers(handleDone: (sink) {
if (!isCompleted) {
receivePort.close();
streamCompleter.setSourceStream(Stream.empty());
streamCompleter.setSourceStream(const Stream.empty());
sinkCompleter.setDestinationSink(NullStreamSink<T>());
}
sink.close();
Expand Down
3 changes: 2 additions & 1 deletion pkgs/stream_channel/lib/src/multi_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ class _MultiChannel<T> extends StreamChannelMixin<T>
// If the inner channel has already closed, create new virtual channels in a
// closed state.
if (_inner == null) {
return VirtualChannel._(this, inputId, Stream.empty(), NullStreamSink());
return VirtualChannel._(
this, inputId, const Stream.empty(), NullStreamSink());
}

late StreamChannelController<T> controller;
Expand Down
2 changes: 1 addition & 1 deletion pkgs/stream_channel/lib/src/stream_channel_completer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class StreamChannelCompleter<T> {
/// instead contain just that error. The sink will silently discard all
/// events.
static StreamChannel fromFuture(Future<StreamChannel> channelFuture) {
var completer = StreamChannelCompleter();
var completer = StreamChannelCompleter<void>();
channelFuture.then(completer.setChannel, onError: completer.setError);
return completer.channel;
}
Expand Down
6 changes: 3 additions & 3 deletions pkgs/stream_channel/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
name: stream_channel
version: 2.1.2
version: 2.1.3-wip
description: >-
An abstraction for two-way communication channels based on the Dart Stream
class.
repository: https://github.com/dart-lang/stream_channel

environment:
sdk: '>=2.19.0 <3.0.0'
sdk: ^3.3.0

dependencies:
async: ^2.5.0

dev_dependencies:
dart_flutter_team_lints: ^1.0.0
dart_flutter_team_lints: ^2.0.0
test: ^1.16.0
16 changes: 8 additions & 8 deletions pkgs/stream_channel/test/disconnector_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ void main() {
late Disconnector disconnector;
late StreamChannel channel;
setUp(() {
streamController = StreamController();
sinkController = StreamController();
streamController = StreamController<void>();
sinkController = StreamController<void>();
disconnector = Disconnector();
channel = StreamChannel.withGuarantees(
streamController.stream, sinkController.sink)
Expand Down Expand Up @@ -52,7 +52,7 @@ void main() {
});

test("events can't be added while a stream is being added", () {
var controller = StreamController();
var controller = StreamController<void>();
channel.sink.addStream(controller.stream);

expect(() => channel.sink.add(1), throwsStateError);
Expand All @@ -67,7 +67,7 @@ void main() {

test('cancels addStream when disconnected', () async {
var canceled = false;
var controller = StreamController(onCancel: () {
var controller = StreamController<void>(onCancel: () {
canceled = true;
});
expect(channel.sink.addStream(controller.stream), completes);
Expand All @@ -78,9 +78,9 @@ void main() {
});

test('disconnect() returns the close future from the inner sink', () async {
var streamController = StreamController();
var sinkController = StreamController();
var disconnector = Disconnector();
var streamController = StreamController<void>();
var sinkController = StreamController<void>();
var disconnector = Disconnector<void>();
var sink = _CloseCompleterSink(sinkController.sink);
StreamChannel.withGuarantees(streamController.stream, sink)
.transform(disconnector);
Expand Down Expand Up @@ -140,7 +140,7 @@ void main() {
/// returned by [close] using [completer].
class _CloseCompleterSink extends DelegatingStreamSink {
/// The completer for the future returned by [close].
final completer = Completer();
final completer = Completer<void>();

_CloseCompleterSink(super.inner);

Expand Down
8 changes: 4 additions & 4 deletions pkgs/stream_channel/test/isolate_channel_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void main() {
});

test("events can't be added while a stream is being added", () {
var controller = StreamController();
var controller = StreamController<void>();
channel.sink.addStream(controller.stream);

expect(() => channel.sink.add(1), throwsStateError);
Expand Down Expand Up @@ -109,7 +109,7 @@ void main() {
test('the sink closes as soon as an error is added via addStream',
() async {
var canceled = false;
var controller = StreamController(onCancel: () {
var controller = StreamController<void>(onCancel: () {
canceled = true;
});

Expand Down Expand Up @@ -156,7 +156,7 @@ void main() {

test('the receiving channel produces an error if it gets the wrong message',
() {
var connectedChannel = IsolateChannel.connectReceive(connectPort);
var connectedChannel = IsolateChannel<int>.connectReceive(connectPort);
connectPort.sendPort.send('wrong value');

expect(connectedChannel.stream.toList(), throwsStateError);
Expand All @@ -165,7 +165,7 @@ void main() {

test('the receiving channel closes gracefully without a connection',
() async {
var connectedChannel = IsolateChannel.connectReceive(connectPort);
var connectedChannel = IsolateChannel<int>.connectReceive(connectPort);
await connectedChannel.sink.close();
await expectLater(connectedChannel.stream.toList(), completion(isEmpty));
await expectLater(connectedChannel.sink.done, completes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ void main() {
test('synchronously throws if an unencodable object is added', () {
var transformed = channel.transform(jsonDocument);
expect(() => transformed.sink.add(Object()),
throwsA(TypeMatcher<JsonUnsupportedObjectError>()));
throwsA(const TypeMatcher<JsonUnsupportedObjectError>()));
});
}
4 changes: 2 additions & 2 deletions pkgs/stream_channel/test/stream_channel_completer_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ void main() {
late StreamChannel innerChannel;
setUp(() {
completer = StreamChannelCompleter();
streamController = StreamController();
sinkController = StreamController();
streamController = StreamController<void>();
sinkController = StreamController<void>();
innerChannel = StreamChannel(streamController.stream, sinkController.sink);
});

Expand Down
44 changes: 30 additions & 14 deletions pkgs/stream_channel/test/stream_channel_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,17 @@ import 'package:stream_channel/stream_channel.dart';
import 'package:test/test.dart';

void main() {
late StreamController streamController;
late StreamController sinkController;
late StreamChannel channel;
setUp(() {
streamController = StreamController();
sinkController = StreamController();
channel = StreamChannel(streamController.stream, sinkController.sink);
});

test("pipe() pipes data from each channel's stream into the other's sink",
() {
var otherStreamController = StreamController();
var otherSinkController = StreamController();
var otherStreamController = StreamController<int>();
var otherSinkController = StreamController<int>();
var otherChannel =
StreamChannel(otherStreamController.stream, otherSinkController.sink);

var streamController = StreamController<int>();
var sinkController = StreamController<int>();
var channel = StreamChannel(streamController.stream, sinkController.sink);

channel.pipe(otherChannel);

streamController.add(1);
Expand All @@ -41,6 +37,10 @@ void main() {
});

test('transform() transforms the channel', () async {
var streamController = StreamController<List<int>>();
var sinkController = StreamController<List<int>>();
var channel = StreamChannel(streamController.stream, sinkController.sink);

var transformed = channel
.cast<List<int>>()
.transform(StreamChannelTransformer.fromCodec(utf8));
Expand All @@ -59,6 +59,10 @@ void main() {
});

test('transformStream() transforms only the stream', () async {
var streamController = StreamController<String>();
var sinkController = StreamController<String>();
var channel = StreamChannel(streamController.stream, sinkController.sink);

var transformed =
channel.cast<String>().transformStream(const LineSplitter());

Expand All @@ -75,8 +79,12 @@ void main() {
});

test('transformSink() transforms only the sink', () async {
var streamController = StreamController<String>();
var sinkController = StreamController<String>();
var channel = StreamChannel(streamController.stream, sinkController.sink);

var transformed = channel.cast<String>().transformSink(
StreamSinkTransformer.fromStreamTransformer(const LineSplitter()));
const StreamSinkTransformer.fromStreamTransformer(LineSplitter()));

streamController.add('fbl\nthp');
unawaited(streamController.close());
Expand All @@ -91,7 +99,11 @@ void main() {
});

test('changeStream() changes the stream', () {
var newController = StreamController();
var streamController = StreamController<int>();
var sinkController = StreamController<int>();
var channel = StreamChannel(streamController.stream, sinkController.sink);

var newController = StreamController<int>();
var changed = channel.changeStream((stream) {
expect(stream, equals(channel.stream));
return newController.stream;
Expand All @@ -107,7 +119,11 @@ void main() {
});

test('changeSink() changes the sink', () {
var newController = StreamController();
var streamController = StreamController<int>();
var sinkController = StreamController<int>();
var channel = StreamChannel(streamController.stream, sinkController.sink);

var newController = StreamController<int>();
var changed = channel.changeSink((sink) {
expect(sink, equals(channel.sink));
return newController.sink;
Expand Down
2 changes: 1 addition & 1 deletion pkgs/stream_channel/test/with_close_guarantee_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void main() {
.listen(expectAsync1((event) {
if (event == 2) channel.sink.close();
}, count: 2))
.asFuture(),
.asFuture<void>(),
completes);

await pumpEventQueue();
Expand Down
16 changes: 8 additions & 8 deletions pkgs/stream_channel/test/with_guarantees_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ void main() {
late StreamController sinkController;
late StreamChannel channel;
setUp(() {
streamController = StreamController();
sinkController = StreamController();
streamController = StreamController<void>();
sinkController = StreamController<void>();
channel = StreamChannel.withGuarantees(
streamController.stream, sinkController.sink);
});
Expand Down Expand Up @@ -53,7 +53,7 @@ void main() {
.listen(expectAsync1((event) {
if (event == 2) channel.sink.close();
}, count: 2))
.asFuture(),
.asFuture<void>(),
completes);
});

Expand Down Expand Up @@ -126,7 +126,7 @@ void main() {
});

test("events can't be added while a stream is being added", () {
var controller = StreamController();
var controller = StreamController<void>();
channel.sink.addStream(controller.stream);

expect(() => channel.sink.add(1), throwsStateError);
Expand All @@ -140,8 +140,8 @@ void main() {

group('with allowSinkErrors: false', () {
setUp(() {
streamController = StreamController();
sinkController = StreamController();
streamController = StreamController<void>();
sinkController = StreamController<void>();
channel = StreamChannel.withGuarantees(
streamController.stream, sinkController.sink,
allowSinkErrors: false);
Expand All @@ -166,7 +166,7 @@ void main() {
.listen(expectAsync1((event) {
if (event == 2) channel.sink.addError('oh no');
}, count: 2))
.asFuture(),
.asFuture<void>(),
completes);
});

Expand All @@ -180,7 +180,7 @@ void main() {
'adding an error via via addStream causes the stream to emit a done '
'event', () async {
var canceled = false;
var controller = StreamController(onCancel: () {
var controller = StreamController<void>(onCancel: () {
canceled = true;
});

Expand Down

0 comments on commit 45fbe10

Please sign in to comment.