addToDownloadQueue method

Future<Completer<void>> addToDownloadQueue(
  1. String url,
  2. String filePath
)

Add a url to the download queue.

Returns

  • A Completer that completes when the download is done.

Note

  • Operates on the Main Isolate

Implementation

Future<Completer<void>> addToDownloadQueue(String url, String filePath) async {
  // If Spawned Isolate is closed, throw an error.
  if (_isClosed) {
    throw StateError('Downloader is closed');
  }

  // This completer is used to ensure that the spawned Isolate has processed the request,
  // and that a request is removed from the activeRequests map only after download.
  // It is completed in _verifyRequestProcessing.
  final activeRequestsLock = Completer<void>.sync();
  final id = _idIndex++;

  _activeRequests[id] = activeRequestsLock;
  _toSpawnedIsolate.send((id, url, filePath));

  return activeRequestsLock;
}