run<Request_T, Response_T> method

Future<Response_T> run<Request_T, Response_T>({
  1. required AsyncTask<Request_T, Response_T> task,
  2. Request_T? request,
})

Implementation

Future<Response_T> run<Request_T, Response_T>({
  required AsyncTask<Request_T, Response_T> task,
  Request_T? request,
}) async {
  await _lock.lock();
  try {
    // Port to the isolate that executes the request.
    final asyncIsolatePort = await _asyncIsolatePort();
    // Create the request.
    final asyncRequest = _AsyncRequestWithoutCallback<Request_T, Response_T>(
      task,
      request,
    );
    // Completer used to return the future response.
    final completer = Completer<Response_T>();
    _asyncCalls[asyncRequest.id] = _AsyncCall<Response_T, dynamic>(
      completer,
      asyncRequest,
      null,
      null,
      null,
    );
    asyncIsolatePort.send(asyncRequest);
    return completer.future;
  } finally {
    _lock.unlock();
  }
}