1<?php
2
3namespace Amp\Parallel\Worker;
4
5/**
6 * An interface for worker pools.
7 */
8interface Pool extends Worker
9{
10    /** @var int The default maximum pool size. */
11    const DEFAULT_MAX_SIZE = 32;
12
13    /**
14     * Gets a worker from the pool. The worker is marked as busy and will only be reused if the pool runs out of
15     * idle workers. The worker will be automatically marked as idle once no references to the returned worker remain.
16     *
17     * @return \Amp\Parallel\Worker\Worker
18     *
19     * @throws \Amp\Parallel\Context\StatusError If the queue is not running.
20     */
21    public function getWorker(): Worker;
22
23    /**
24     * Gets the number of workers currently running in the pool.
25     *
26     * @return int The number of workers.
27     */
28    public function getWorkerCount(): int;
29
30    /**
31     * Gets the number of workers that are currently idle.
32     *
33     * @return int The number of idle workers.
34     */
35    public function getIdleWorkerCount(): int;
36
37    /**
38     * Gets the maximum number of workers the pool may spawn to handle concurrent tasks.
39     *
40     * @return int The maximum number of workers.
41     */
42    public function getMaxSize(): int;
43}
44