initialize method

Future<bool> initialize()

Initializes the worker isolate and ODBC environment.

  1. Spawns a new isolate via Isolate.spawn.
  2. Loads the ODBC driver in the worker.
  3. Initializes the ODBC environment there.
  4. 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;
}