2016-12-29 19:16:04 -06:00
|
|
|
<?php
|
2016-08-18 11:04:48 -05:00
|
|
|
|
2016-08-23 16:47:40 -05:00
|
|
|
namespace Amp\Parallel\Worker;
|
2015-08-14 12:25:07 -05:00
|
|
|
|
|
|
|
/**
|
2015-12-04 23:50:32 -06:00
|
|
|
* An interface for worker pools.
|
2015-08-14 12:25:07 -05:00
|
|
|
*/
|
2018-10-07 09:50:45 -05:00
|
|
|
interface Pool extends Worker
|
|
|
|
{
|
2016-08-26 10:10:03 -05:00
|
|
|
/** @var int The default maximum pool size. */
|
2015-12-16 15:53:53 -06:00
|
|
|
const DEFAULT_MAX_SIZE = 32;
|
|
|
|
|
2016-01-14 18:54:53 -06:00
|
|
|
/**
|
|
|
|
* Gets a worker from the pool. The worker is marked as busy and will only be reused if the pool runs out of
|
|
|
|
* idle workers. The worker will be automatically marked as idle once no references to the returned worker remain.
|
|
|
|
*
|
2016-08-23 16:47:40 -05:00
|
|
|
* @return \Amp\Parallel\Worker\Worker
|
2016-01-14 18:54:53 -06:00
|
|
|
*
|
2017-12-07 21:26:55 -06:00
|
|
|
* @throws \Amp\Parallel\Context\StatusError If the queue is not running.
|
2016-01-14 18:54:53 -06:00
|
|
|
*/
|
2016-01-23 00:00:56 -06:00
|
|
|
public function get(): Worker;
|
2016-01-14 18:54:53 -06:00
|
|
|
|
2015-08-28 20:30:53 -05:00
|
|
|
/**
|
2015-12-04 23:50:32 -06:00
|
|
|
* Gets the number of workers currently running in the pool.
|
2015-08-27 22:51:50 -05:00
|
|
|
*
|
2015-12-04 23:50:32 -06:00
|
|
|
* @return int The number of workers.
|
2015-08-27 22:51:50 -05:00
|
|
|
*/
|
2016-01-23 00:00:56 -06:00
|
|
|
public function getWorkerCount(): int;
|
2015-08-27 22:51:50 -05:00
|
|
|
|
|
|
|
/**
|
2015-12-04 23:50:32 -06:00
|
|
|
* Gets the number of workers that are currently idle.
|
2015-08-27 22:51:50 -05:00
|
|
|
*
|
2015-12-04 23:50:32 -06:00
|
|
|
* @return int The number of idle workers.
|
2015-08-27 22:51:50 -05:00
|
|
|
*/
|
2016-01-23 00:00:56 -06:00
|
|
|
public function getIdleWorkerCount(): int;
|
2015-12-16 15:53:53 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the maximum number of workers the pool may spawn to handle concurrent tasks.
|
|
|
|
*
|
|
|
|
* @return int The maximum number of workers.
|
|
|
|
*/
|
2016-01-23 00:00:56 -06:00
|
|
|
public function getMaxSize(): int;
|
2015-08-14 12:25:07 -05:00
|
|
|
}
|