configureCompressionIsolatePool function

bool configureCompressionIsolatePool({
  1. int totalWorkers = 1,
  2. int? maxIsolates,
})

Configures the compressionIsolatePool of the current isolate for a server with totalWorkers isolates, each with its own pool: APIIsolatePool.defaultMaxIsolatesFor (or maxIsolates).

The pool is only replaced if unused (no isolates and nothing queued). Returns true if compressionIsolatePool has the requested size.

Implementation

bool configureCompressionIsolatePool({int totalWorkers = 1, int? maxIsolates}) {
  maxIsolates ??= APIIsolatePool.defaultMaxIsolatesFor(workers: totalWorkers);

  var pool = compressionIsolatePool;
  if (pool.maxIsolates == maxIsolates && !pool.isClosed) return true;

  if (!pool.isClosed && (pool.isolatesLength > 0 || pool.queuedLength > 0)) {
    _log.warning(
      "Can't resize the `compressionIsolatePool` in use to `maxIsolates: $maxIsolates`: $pool",
    );
    return false;
  }

  pool.close();
  compressionIsolatePool = APIIsolatePool(
    maxIsolates: maxIsolates,
    idleTimeout: pool.idleTimeout,
    debugName: pool.debugName,
  );
  return true;
}