execute<T, T2> static method

Future<T> execute<T, T2>(
  1. FutureOr<T> fn(
    1. T2
    ),
  2. T2 arg
)

Implementation

static Future<T> execute<T, T2>(FutureOr<T> Function(T2) fn, T2 arg) async {
  if (_sendPort != null) {
    var receivePort = ReceivePort();
    _sendPort!.send(
        _WorkerRequest(fn: fn, arg: arg, replyTo: receivePort.sendPort));
    var res = await receivePort.first;
    receivePort.close();
    return res;
  }
  throw Exception('worker must be initialized before use');
}