shutdown method

Future<void> shutdown({
  1. Duration timeout = const Duration(seconds: 2),
})

Gracefully shuts down the pool, completing pending tasks.

timeout — Maximum time to wait for pending tasks to complete.

Implementation

Future<void> shutdown({Duration timeout = const Duration(seconds: 2)}) async {
  _isShuttingDown = true;

  // Cancel pending tasks
  for (final task in _taskQueue) {
    if (!task.completer.isCompleted) {
      task.completer.completeError(
        FrameDroppedException('Pool shutting down'),
      );
    }
  }
  _taskQueue.clear();

  // Kill workers
  for (final worker in _workers) {
    worker.kill();
  }
  _workers.clear();

  _isInitialized = false;
  _isShuttingDown = false;
}