initialize method
Initializes the worker isolate and ODBC environment.
- Spawns a new isolate via Isolate.spawn.
- Loads the ODBC driver in the worker.
- Initializes the ODBC environment there.
- Returns when the worker is ready to accept requests.
One-time cost is typically ~50–100 ms. Safe to call multiple times; later calls return immediately if already initialized.
Returns true if initialization succeeds, false otherwise.
Implementation
Future<bool> initialize() async {
if (_isInitialized) return true;
_isShuttingDown = false;
_workers.clear();
for (var i = 0; i < workerCount; i++) {
_workers.add(await _spawnWorker(i));
}
var initialized = true;
for (final worker in _workers) {
final initResp = await _sendRequestOnWorker<InitializeResponse>(
worker,
InitializeRequest(_nextRequestId()),
);
initialized = initialized && initResp.success;
}
_isInitialized = initialized;
return initialized;
}