dispose method

Future<void> dispose()

Disposes the isolate and cleans up resources

Implementation

Future<void> dispose() async {
  _isolate?.kill(priority: Isolate.immediate);
  _isolate = null;
  _receivePort?.close();
  _receivePort = null;
  _isolateSendPort = null;
  _isInitialized = false;

  // Complete any pending jobs with an error
  for (final completer in _jobCompleterMap.values) {
    completer.completeError(StateError('IsolateWorker disposed'));
  }
  _jobCompleterMap.clear();
}