Skip to content

Commit

Permalink
Fix a bug where toNSInputStream would leak if the stream is closed be…
Browse files Browse the repository at this point in the history
…fore being fully read
  • Loading branch information
brianquinlan committed Oct 17, 2024
1 parent 10077a4 commit a2b89f4
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pkgs/objective_c/lib/src/ns_input_stream.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,15 @@ extension NSInputStreamStreamExtension on Stream<List<int>> {

dataSubscription.pause();
port.listen((count) {
print('Got $count');
// -1 indicates that the `NSInputStream` is closed. All other values
// indicate that the `NSInputStream` needs more data.
//
// If [DartInputStreamAdapter.setError_] or
// [DartInputStreamAdapter.setDone] is called then the close message (-1)
// will not be sent when the input stream is closed.
if (count == -1) {
dataSubscription.cancel();
port.close();
} else {
dataSubscription.resume();
}
Expand Down

0 comments on commit a2b89f4

Please sign in to comment.