runWithStream<Request_T, Response_T, Message_T> method

Future<Response_T> runWithStream<Request_T, Response_T, Message_T>({
  1. required AsyncTaskWithSend<Request_T, Response_T, Message_T> task,
  2. required StreamController<Message_T> stream,
  3. Request_T? request,
})

Implementation

Future<Response_T> runWithStream<Request_T, Response_T, Message_T>({
  required AsyncTaskWithSend<Request_T, Response_T, Message_T> task,
  required StreamController<Message_T> stream,
  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 =
        _AsyncRequestWithCallback<Request_T, Response_T, Message_T>(
      task,
      request,
    );
    // Completer used to return the future response.
    final completer = Completer<Response_T>();
    _asyncCalls[asyncRequest.id] = _AsyncCall<Response_T, Message_T>(
      completer,
      asyncRequest,
      stream,
      null,
      null,
    );
    asyncIsolatePort.send(asyncRequest);
    return completer.future;
  } finally {
    _lock.unlock();
  }
}