commit | 0743f116df2657458a5a5d4b60863a041ba7832b | [log] [tgz] |
---|---|---|
author | Parker Lougheed <parlough@gmail.com> | Fri Jun 16 09:30:39 2023 -0500 |
committer | GitHub <noreply@github.com> | Fri Jun 16 07:30:39 2023 -0700 |
tree | ca950c62e97ac23fa8a95d84fd41692f62360cc5 | |
parent | c14a2687728081adc14c12fa50165e785326275c [diff] |
Require protobuf 3.0.0 and prepare for 1.0.3 release (#75) Since build_web_compilers depends on this package, the previous constraint will limit many projects from (easily) moving to protobuf 3.0.0 and benefiting from its fixes.
Tools for creating a persistent worker loop for bazel.
There are two abstract classes provided by this package, AsyncWorkerLoop
and SyncWorkerLoop
. These each have a performRequest
method which you must implement.
Lets look at a simple example of a SyncWorkerLoop
implementation:
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 { /// Must synchronously return a [WorkResponse], since this is a /// [SyncWorkerLoop]. WorkResponse performRequest(WorkRequest request) { File('hello.txt').writeAsStringSync('hello world!'); return WorkResponse()..exitCode = EXIT_CODE_OK; } }
And now the same thing, implemented as an AsyncWorkerLoop
:
import 'dart:io'; import 'package:bazel_worker/bazel_worker.dart'; void main() { // Doesn't block, runs tasks async as they are received on stdin. AsyncSimpleWorker().run(); } class AsyncSimpleWorker extends AsyncWorkerLoop { /// Must return a [Future<WorkResponse>], since this is an /// [AsyncWorkerLoop]. Future<WorkResponse> performRequest(WorkRequest request) async { await File('hello.txt').writeAsString('hello world!'); return WorkResponse()..exitCode = EXIT_CODE_OK; } }
As you can see, these are nearly identical, it mostly comes down to the constraints on your package and personal preference which one you choose to implement.
A package:bazel_worker/testing.dart
file is also provided, which can greatly assist with writing unit tests for your worker. See the test/worker_loop_test.dart
test included in this package for an example of how the helpers can be used.
Please file feature requests and bugs at the issue tracker.