dispose method

Future<void> dispose()

Disposes the pool, cancels all subscriptions, kills all isolates, closes ports and the stream controller, and resets task IDs.

Implementation

Future<void> dispose() async {
  for (var isolate in _isolateList) {
    await isolate.subscription?.cancel();
    isolate.controlPort?.send(DownloadIsolateMsg(
      IsolateMsgType.task,
      isolate.task?..status = DownloadStatus.CANCELLED,
    ));
    isolate.receivePort.close();
    isolate.isolate.kill(priority: Isolate.immediate);
  }
  _isolateList.clear();
  _taskList.clear();
  await _streamController.close();
  DownloadTask.resetId();
}