-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy paththread_pool.stub.php
More file actions
75 lines (62 loc) · 1.96 KB
/
thread_pool.stub.php
File metadata and controls
75 lines (62 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
/** @generate-class-entries */
namespace Async;
/**
* ThreadPool manages a fixed set of reusable worker threads.
* Tasks are submitted and distributed to workers via an internal channel.
* The pool can be transferred between threads (shared persistent memory).
*
* @strict-properties
* @not-serializable
*/
final class ThreadPool
{
/**
* @param int $workers Number of worker threads.
* @param int $queueSize Maximum pending task queue size (default: workers * 4).
*/
public function __construct(int $workers, int $queueSize = 0) {}
/**
* Submit a task for execution. Returns a Future that resolves
* with the task's return value or rejects with its exception.
*/
public function submit(callable $task, mixed ...$args): Future {}
/**
* Apply a callable to each item in parallel across worker threads.
* Returns an array of results in the same order as the input.
*/
public function map(array $items, callable $task): array {}
/**
* Close the pool — reject new submissions but let running tasks finish.
*/
public function close(): void {}
/**
* Cancel all pending tasks and stop workers.
*/
public function cancel(): void {}
/**
* Whether the pool is closed (no new submissions accepted).
*/
public function isClosed(): bool {}
/**
* Number of tasks waiting in the queue.
*/
public function getPendingCount(): int {}
/**
* Number of tasks currently being executed by workers.
*/
public function getRunningCount(): int {}
/**
* Number of tasks that have completed (successfully or with exception)
* since the pool was created. Monotonically increasing.
*/
public function getCompletedCount(): int {}
/**
* Number of worker threads.
*/
public function getWorkerCount(): int {}
}
/**
* Exception thrown by ThreadPool operations.
*/
class ThreadPoolException extends \Exception {}