1 | | | import 'channel.dart'; |
2 | | | import 'local_worker.dart'; |
3 | | | import 'worker_request.dart'; |
4 | | | import 'worker_service.dart'; |
5 | | |
|
6 | | | /// Base class used to communicate with a [LocalWorker]. |
7 | | | /// |
8 | | | /// Typically, derived classes should add proxy methods sending [WorkerRequest]s to the worker. |
9 | | | class LocalWorkerClient implements WorkerService { |
10 | | | /// Create a client for a [LocalWorker]. The [channel] passed to this client must have been obtained by |
11 | | | /// calling [Channel.share] on the [LocalWorker.channel]. |
12 | | 1 | LocalWorkerClient(this.channel); |
13 | | |
|
14 | | | /// The [Channel] to communicate with the [LocalWorker]. |
15 | | | final Channel channel; |
16 | | |
|
17 | | | /// Sends a command to the [LocalWorker]. |
18 | | 1 | Future<T> send<T>(int command, List args) => |
19 | | 2 | channel.sendRequest<T>(command, args); |
20 | | |
|
21 | | | /// Sends a streaming command to the [LocalWorker]. |
22 | | 1 | Stream<T> stream<T>(int command, List args) => |
23 | | 2 | channel.sendStreamingRequest<T>(command, args); |
24 | | |
|
25 | | | /// Local worker clients do not need an [operations] map. |
26 | | | @override |
27 | | | final Map<int, CommandHandler> operations = WorkerService.noOperations; |
28 | | | } |