-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy paththread_channel.stub.php
More file actions
89 lines (77 loc) · 2.38 KB
/
Copy paththread_channel.stub.php
File metadata and controls
89 lines (77 loc) · 2.38 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
/** @generate-class-entries */
namespace Async;
/**
* Exception thrown when attempting to send to or receive from a closed thread channel.
*/
class ThreadChannelException extends AsyncException {}
/**
* Thread-safe channel for message passing between PHP threads.
*
* Unlike Channel (coroutine-only), ThreadChannel uses persistent memory
* and pthread_mutex for cross-thread safety. Data is transferred via
* deep copy (pemalloc).
*
* Always buffered (capacity >= 1). No rendezvous mode.
*
* @strict-properties
* @not-serializable
*/
final class ThreadChannel implements Awaitable, \Countable
{
/**
* Create a new thread-safe channel.
*
* @param int $capacity Buffer size (must be >= 1)
*/
public function __construct(int $capacity = 16) {}
/**
* Send a value into the channel (blocking).
*
* Suspends the current coroutine until buffer space is available.
* The value is deep-copied into persistent memory.
*
* @param Completable|null $cancellationToken Optional cancellation token
* @throws ThreadChannelException if channel is closed
*/
public function send(mixed $value, ?Completable $cancellationToken = null): void {}
/**
* Receive a value from the channel (blocking).
*
* Suspends the current coroutine until a value is available.
* The value is copied from persistent memory into the current thread.
*
* @param Completable|null $cancellationToken Optional cancellation token
* @throws ThreadChannelException if channel is closed and empty
*/
public function recv(?Completable $cancellationToken = null): mixed {}
/**
* Close the channel.
*
* After closing:
* - send() throws ThreadChannelException
* - recv() drains remaining values, then throws ThreadChannelException
* - All waiting coroutines are woken with ThreadChannelException
*/
public function close(): void {}
/**
* Check whether the channel is closed.
*/
public function isClosed(): bool {}
/**
* Get channel capacity.
*/
public function capacity(): int {}
/**
* Current number of buffered values.
*/
public function count(): int {}
/**
* Check if channel is empty.
*/
public function isEmpty(): bool {}
/**
* Check if channel is full.
*/
public function isFull(): bool {}
}