Skip to content
This repository has been archived by the owner on Nov 1, 2024. It is now read-only.

Make Stdin act like a Stream<Uint8List> #39

Merged
merged 2 commits into from
May 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions 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 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 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 <misc@dartlang.org>
Expand Down