| 1 |  |  | import 'dart:async'; | 
                
                
                    | 2 |  |  |  | 
                
                
                    | 3 |  |  | import 'package:cancelation_token/cancelation_token.dart'; | 
                
                
                    | 4 |  |  | import 'package:using/using.dart'; | 
                
                
                    | 5 |  |  |  | 
                
                
                    | 6 |  |  | import '../channel.dart'; | 
                
                
                    | 7 |  |  | import '../invoker.dart'; | 
                
                
                    | 8 |  |  | import '../tokens/_squadron_cancelation_token.dart'; | 
                
                
                    | 9 |  |  | import '../typedefs.dart'; | 
                
                
                    | 10 |  |  | import '../worker/worker_request.dart'; | 
                
                
                    | 11 |  |  | import '../worker_service.dart'; | 
                
                
                    | 12 |  |  | import 'local_worker.dart'; | 
                
                
                    | 13 |  |  |  | 
                
                
                    | 14 |  |  | /// Base class used to communicate with a [LocalWorker]. | 
                
                
                    | 15 |  |  | /// | 
                
                
                    | 16 |  |  | /// Typically, derived classes should add proxy methods sending [WorkerRequest]s to the worker. | 
                
                
                    | 17 |  |  | class LocalWorkerClient with Releasable implements WorkerService, Invoker { | 
                
                
                    | 18 |  |  |   /// Create a client for a [LocalWorker]. The [channel] passed to this client must have been obtained by | 
                
                
                    | 19 |  |  |   /// calling [Channel.share] on the [LocalWorker.channel]. | 
                
                
                    | 20 |  | 1 |   LocalWorkerClient(this.channel); | 
                
                
                    | 21 |  |  |  | 
                
                
                    | 22 |  |  |   /// The [Channel] to communicate with the [LocalWorker]. | 
                
                
                    | 23 |  |  |   final Channel channel; | 
                
                
                    | 24 |  |  |  | 
                
                
                    | 25 |  | 0 |   @override | 
                
                
                    | 26 |  |  |   void release() { | 
                
                
                    | 27 |  | 0 |     channel.close(); | 
                
                
                    | 28 |  | 0 |     super.release(); | 
                
                
                    | 29 |  |  |   } | 
                
                
                    | 30 |  |  |  | 
                
                
                    | 31 |  |  |   /// Sends a command to the [LocalWorker]. | 
                
                
                    | 32 |  | 1 |   @override | 
                
                
                    | 33 |  |  |   Future<dynamic> send(int command, | 
                
                
                    | 34 |  |  |           {List args = const [], | 
                
                
                    | 35 |  |  |           CancelationToken? token, | 
                
                
                    | 36 |  |  |           bool inspectRequest = false, | 
                
                
                    | 37 |  |  |           bool inspectResponse = false}) => | 
                
                
                    | 38 |  | 2 |       channel.sendRequest(command, args, | 
                
                
                    | 39 |  | 0 |           token: token?.wrap(), | 
                
                
                    | 40 |  |  |           inspectRequest: inspectRequest, | 
                
                
                    | 41 |  |  |           inspectResponse: inspectResponse); | 
                
                
                    | 42 |  |  |  | 
                
                
                    | 43 |  |  |   /// Sends a streaming command to the [LocalWorker]. | 
                
                
                    | 44 |  | 1 |   @override | 
                
                
                    | 45 |  |  |   Stream<dynamic> stream(int command, | 
                
                
                    | 46 |  |  |           {List args = const [], | 
                
                
                    | 47 |  |  |           CancelationToken? token, | 
                
                
                    | 48 |  |  |           bool inspectRequest = false, | 
                
                
                    | 49 |  |  |           bool inspectResponse = false}) => | 
                
                
                    | 50 |  | 2 |       channel.sendStreamingRequest(command, args, | 
                
                
                    | 51 |  | 0 |           token: token?.wrap(), | 
                
                
                    | 52 |  |  |           inspectRequest: inspectRequest, | 
                
                
                    | 53 |  |  |           inspectResponse: inspectResponse); | 
                
                
                    | 54 |  |  |  | 
                
                
                    | 55 |  |  |   /// Local worker clients do not need an [operations] map. | 
                
                
                    | 56 |  |  |   @override | 
                
                
                    | 57 |  |  |   final OperationsMap operations = WorkerService.noOperations; | 
                
                
                    | 58 |  |  | } |