1 | <?php |
||
10 | class Pool |
||
11 | { |
||
12 | /** |
||
13 | * Workers in the pool. |
||
14 | * @var array |
||
15 | */ |
||
16 | protected $workers = []; |
||
17 | |||
18 | /** |
||
19 | * Options for the pool. |
||
20 | * @var array |
||
21 | */ |
||
22 | protected $options; |
||
23 | |||
24 | /** |
||
25 | * Pool singletons. |
||
26 | * @var Pool[] |
||
27 | */ |
||
28 | static protected $pools = []; |
||
29 | |||
30 | /** |
||
31 | * Pool constructor. |
||
32 | * |
||
33 | * @param array $options |
||
34 | * Options for the pool. |
||
35 | * - concurrency |
||
36 | * - polling_interval |
||
37 | */ |
||
38 | 6 | public function __construct(array $options = array()) |
|
47 | |||
48 | /** |
||
49 | * Get a singleton pool. |
||
50 | * |
||
51 | * @param string $name |
||
52 | * Name of pool. |
||
53 | * @param array $options |
||
54 | * Options for the pool. |
||
55 | * |
||
56 | * @return \Gielfeldt\SimpleWorker\Pool |
||
57 | */ |
||
58 | 1 | public static function get($name, array $options = array()) |
|
65 | |||
66 | /** |
||
67 | * Add a worker to the pool. |
||
68 | * |
||
69 | * @param \Gielfeldt\SimpleWorker\SimpleWorkerInterface $worker |
||
70 | * The worker to add. |
||
71 | * @param $callback |
||
72 | * The callback to fire when ready. |
||
73 | */ |
||
74 | 4 | public function addWorker(SimpleWorkerInterface $worker, $callback) |
|
78 | |||
79 | /** |
||
80 | * Add multiple workers to the pool. |
||
81 | * |
||
82 | * @param \Gielfeldt\SimpleWorker\SimpleWorkerInterface[] $workers |
||
83 | * The worker to add. |
||
84 | * @param $callback |
||
85 | * The callback to fire when ready. |
||
86 | */ |
||
87 | 1 | public function addWorkers(array $workers, $callback) |
|
93 | |||
94 | /** |
||
95 | * Process workers. |
||
96 | */ |
||
97 | 4 | public function process(array $options = array()) |
|
131 | } |
||
132 |