compute method

Future<R> compute(
  1. I payload
)
override

Spin up a short lived worker, execute the entrypoint and get the result

Implementation

Future<R> compute(I payload) async {
  final completer = Completer<R>();
  final id = getID();
  _tasks[id] = completer;
  _toIsolate.send((id, payload));

  try {
    final future = completer.future;

    if (timeoutDuration != null) {
      return await future.timeout(timeoutDuration!);
    }
    return await future;
  } catch (e) {
    _tasks.remove(id);
    rethrow;
  }
}