close method

void close()

Stop the workers. Running and waiting tasks fail with a StateError. A connected isolate only stops sending to the owner. A later run starts a new pool.

Implementation

void close() {
  // ponytail: after this, a compute call in the same dying server
  // isolate starts a local pool that nothing closes. Add a closed flag
  // if shutdown code is seen to call compute.
  _owner = null;
  StateError closed = StateError(
    'The compute pool was closed before the task was done. '
    'The server is stopping.',
  );
  for (_Worker worker in _workers) {
    worker.isolate?.kill(priority: Isolate.immediate);
    worker.job?.fail(closed);
  }
  while (_queue.isNotEmpty) {
    _queue.removeFirst().fail(closed);
  }
  _workers.clear();
  _inbox?.close();
  _inbox = null;
}