send method
Future
send(
- int command, {
- List args = const [],
- CancelationToken? token,
- bool inspectRequest = false,
- bool inspectResponse = false,
inherited
Sends a workload to the worker.
Implementation
@override
Future<dynamic> send(
int command, {
List args = const [],
CancelationToken? token,
bool inspectRequest = false,
bool inspectResponse = false,
}) async {
token?.throwIfCanceled();
// get the channel, start the worker if necessary
final channel = _channel ?? await start();
final completer = ForwardCompleter();
final squadronToken = token?.wrap();
squadronToken?.onCanceled.then((ex) {
_channel?.cancelToken(squadronToken);
completer.failure(SquadronException.from(ex, null, command));
});
_stats.beginWork();
completer.future.whenComplete(_stats.endWork).ignore();
try {
final res = await channel.sendRequest(
command,
args,
token: squadronToken,
inspectRequest: inspectRequest,
inspectResponse: inspectResponse,
);
completer.success(res);
} catch (ex, st) {
_stats.failed();
completer.failure(SquadronException.from(ex, st, command));
}
return completer.future;
}