dispose method

void dispose()

Shuts down the worker isolate and releases resources.

Completes any pending requests with error before shutting down. Sends shutdown to the worker, kills the isolate, and closes the receive port. Call when the async connection is no longer needed. After dispose, isInitialized is false and initialize can be called again. In-flight requests will complete with AsyncError (workerTerminated).

Implementation

void dispose() {
  _isShuttingDown = true;
  _failAllPending(
    const AsyncError(
      code: AsyncErrorCode.workerTerminated,
      message: 'Connection disposed; worker shutting down',
    ),
  );
  _isInitialized = false;
  _workerSendPort?.send('shutdown');
  _workerIsolate?.kill();
  _receivePort?.close();
  _namedParamOrderByStmtId.clear();
  _workerSendPort = null;
  _workerIsolate = null;
  _receivePort = null;
}