Expand description, add example (#60)
Improves the pub score.
Other cleanup:
- Remove optional `new` in example code in the README.
- Use `^` constraints where feasible.
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a6980e1..fbaed82 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 1.0.2-dev
+
+* Expand pub documentation to improve pub score.
+
## 1.0.1
* Require Dart SDK >=1.14.0
diff --git a/README.md b/README.md
index 76498e5..51378ee 100644
--- a/README.md
+++ b/README.md
@@ -14,15 +14,15 @@
void main() {
// Blocks until it gets an EOF from stdin.
- new SyncSimpleWorker().run();
+ SyncSimpleWorker().run();
}
class SyncSimpleWorker extends SyncWorkerLoop {
/// Must synchronously return a [WorkResponse], since this is a
/// [SyncWorkerLoop].
WorkResponse performRequest(WorkRequest request) {
- new File('hello.txt').writeAsStringSync('hello world!');
- return new WorkResponse()..exitCode = EXIT_CODE_OK;
+ File('hello.txt').writeAsStringSync('hello world!');
+ return WorkResponse()..exitCode = EXIT_CODE_OK;
}
}
```
@@ -35,15 +35,15 @@
void main() {
// Doesn't block, runs tasks async as they are received on stdin.
- new AsyncSimpleWorker().run();
+ AsyncSimpleWorker().run();
}
class AsyncSimpleWorker extends AsyncWorkerLoop {
/// Must return a [Future<WorkResponse>], since this is an
/// [AsyncWorkerLoop].
Future<WorkResponse> performRequest(WorkRequest request) async {
- await new File('hello.txt').writeAsString('hello world!');
- return new WorkResponse()..exitCode = EXIT_CODE_OK;
+ await File('hello.txt').writeAsString('hello world!');
+ return WorkResponse()..exitCode = EXIT_CODE_OK;
}
}
```
diff --git a/example/README.md b/example/README.md
new file mode 100644
index 0000000..dad3b79
--- /dev/null
+++ b/example/README.md
@@ -0,0 +1,3 @@
+Run `dart example/client.dart`. The client will start up a worker process, send
+a single work request, read a file written by the worker, then terminate the
+worker.
diff --git a/example/client.dart b/example/client.dart
new file mode 100644
index 0000000..12fd305
--- /dev/null
+++ b/example/client.dart
@@ -0,0 +1,22 @@
+import 'dart:io';
+
+import 'package:bazel_worker/driver.dart';
+
+void main() async {
+ var scratchSpace = await Directory.systemTemp.createTemp();
+ var driver = BazelWorkerDriver(
+ () => Process.start(Platform.resolvedExecutable,
+ [Platform.script.resolve('worker.dart').toFilePath()],
+ workingDirectory: scratchSpace.path),
+ maxWorkers: 4);
+ var response = await driver.doWork(WorkRequest()..arguments.add('foo'));
+ if (response.exitCode != EXIT_CODE_OK) {
+ print('Worker request failed');
+ } else {
+ print('Worker request succeeded, file content:');
+ var outputFile = File.fromUri(scratchSpace.uri.resolve('hello.txt'));
+ print(await outputFile.readAsString());
+ }
+ await scratchSpace.delete(recursive: true);
+ await driver.terminateWorkers();
+}
diff --git a/example/worker.dart b/example/worker.dart
new file mode 100644
index 0000000..a59f570
--- /dev/null
+++ b/example/worker.dart
@@ -0,0 +1,15 @@
+import 'dart:io';
+import 'package:bazel_worker/bazel_worker.dart';
+
+void main() {
+ // Blocks until it gets an EOF from stdin.
+ SyncSimpleWorker().run();
+}
+
+class SyncSimpleWorker extends SyncWorkerLoop {
+ @override
+ WorkResponse performRequest(WorkRequest request) {
+ File('hello.txt').writeAsStringSync(request.arguments.first);
+ return WorkResponse()..exitCode = EXIT_CODE_OK;
+ }
+}
diff --git a/pubspec.yaml b/pubspec.yaml
index a791469..dcac9d6 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,15 +1,16 @@
name: bazel_worker
-version: 1.0.1
+version: 1.0.2-dev
-description: Tools for creating a bazel persistent worker.
+description: >-
+ Protocol and utilities to implement or invoke persistent bazel workers.
homepage: https://github.com/dart-lang/bazel_worker
environment:
sdk: '>=2.14.0 <3.0.0'
dependencies:
- async: '>=2.5.0 <3.0.0'
- protobuf: '>=2.0.0 <3.0.0'
+ async: ^2.5.0
+ protobuf: ^2.0.0
dev_dependencies:
lints: ^1.0.0