dispose method
void
dispose()
inherited
Shuts down worker isolates and invalidates Dart resource state. Native cancellation or cleanup cannot be confirmed for blocked calls.
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;
_generation++;
_initialization = null;
_initializationContext = null;
_failAllPending(
const AsyncError(
code: AsyncErrorCode.workerTerminated,
message: 'Connection disposed; worker shutting down',
),
);
_isInitialized = false;
for (final worker in {..._workers, ..._initializingWorkers}) {
_abandonWorker(
worker,
const AsyncError(
code: AsyncErrorCode.workerTerminated,
message: 'Connection disposed; cleanup is not confirmed',
),
);
worker
..failAll(
const AsyncError(
code: AsyncErrorCode.workerTerminated,
message: 'Connection disposed',
),
)
..dispose();
}
_initializingWorkers.clear();
_blockedTransactions.clear();
_blockedXa.clear();
_quarantinedConnections.clear();
_deadConnections.clear();
_resumedXa.clear();
_pendingXaResume.clear();
_workers.clear();
_namedParamOrderByStmtId.clear();
_connectionWorkerById.clear();
_nativeConnectionLifetimes.clear();
_connectionPoolById.clear();
_streamConnectionById.clear();
_asyncRequestConnectionById.clear();
_statementWorkerById.clear();
_statementConnectionById.clear();
_transactionWorkerById.clear();
_transactionConnectionById.clear();
_xaWorkerById.clear();
_xaConnectionById.clear();
_streamWorkerById.clear();
_asyncRequestWorkerById.clear();
}