Skip to content

Commit

Permalink
Make Stdin act like a Stream<Uint8List> (dart-archive/bazel_worker#39)
Browse files Browse the repository at this point in the history
* Make Stdin act like a Stream<Uint8List>

In preparation for dart-lang/sdk#36900

* Bump version, and add changelog entry
  • Loading branch information
tvolkert authored and jakemac53 committed May 20, 2019
1 parent d0ea3c1 commit 036da7d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
4 changes: 4 additions & 0 deletions pkgs/bazel_worker/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.1.21

* Make `TestStdinAsync` behave like a `Stream<Uint8List>`

## 0.1.20

* Close worker `outputStream` on `cancel`.
Expand Down
9 changes: 5 additions & 4 deletions pkgs/bazel_worker/lib/testing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import 'dart:async';
import 'dart:collection';
import 'dart:io';
import 'dart:typed_data';

import 'package:bazel_worker/bazel_worker.dart';

Expand Down Expand Up @@ -50,12 +51,12 @@ class TestStdinSync implements TestStdin {
/// Note: You must call [close] in order for the loop to exit properly.
class TestStdinAsync implements TestStdin {
/// Controls the stream for async delivery of bytes.
final StreamController<List<int>> _controller = new StreamController();
StreamController<List<int>> get controller => _controller;
final StreamController<Uint8List> _controller = new StreamController();
StreamController<Uint8List> get controller => _controller;

/// Adds all the [bytes] to this stream.
void addInputBytes(List<int> bytes) {
_controller.add(bytes);
_controller.add(Uint8List.fromList(bytes));
}

/// Closes this stream. This is necessary for the [AsyncWorkerLoop] to exit.
Expand All @@ -64,7 +65,7 @@ class TestStdinAsync implements TestStdin {
}

@override
StreamSubscription<List<int>> listen(onData(List<int> bytes),
StreamSubscription<Uint8List> listen(onData(Uint8List bytes),
{Function onError, void onDone(), bool cancelOnError}) {
return _controller.stream.listen(onData,
onError: onError, onDone: onDone, cancelOnError: cancelOnError);
Expand Down
2 changes: 1 addition & 1 deletion pkgs/bazel_worker/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: bazel_worker
version: 0.1.20
version: 0.1.21

description: Tools for creating a bazel persistent worker.
author: Dart Team <[email protected]>
Expand Down

0 comments on commit 036da7d

Please sign in to comment.