-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathchannel.stub.php
More file actions
144 lines (128 loc) · 4.08 KB
/
Copy pathchannel.stub.php
File metadata and controls
144 lines (128 loc) · 4.08 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php
/** @generate-class-entries */
namespace Async;
/**
* Why a channel was closed.
*/
enum ChannelCloseReason: string
{
case EXPLICIT = 'explicit';
case DISPOSED = 'disposed';
case NO_PRODUCERS = 'no producers timeout';
case NO_CONSUMERS = 'no consumers timeout';
case DEADLOCK = 'deadlock';
case SCOPE_DISPOSED = 'scope disposed';
}
/**
* Exception thrown when attempting to send to or receive from a closed channel.
*/
class ChannelException extends AsyncException
{
public ChannelCloseReason $reason;
}
/**
* Channel is a concurrency primitive for message passing between coroutines.
*
* The channel can be:
* - unbuffered (capacity = 0): rendezvous semantics, direct handoff
* - buffered (capacity > 0): bounded buffer
*
* @strict-properties
* @not-serializable
*/
final class Channel implements Awaitable, \IteratorAggregate, \Countable
{
/**
* Create a new channel.
*
* @param int $capacity
* 0 = unbuffered (rendezvous) - send blocks until receive
* >0 = bounded buffer
* @param int $noProducerTimeout
* Deadlock timeout (ms) while at least one receiver is blocked waiting
* for data. 0 = disabled (default).
* @param int $noConsumerTimeout
* Deadlock timeout (ms) while at least one sender is blocked waiting
* for space. 0 = disabled (default).
* @param bool $hardTimeouts
* false (default): timers are hidden from the event loop — they do not
* keep the loop alive on their own; the global deadlock resolver is
* eligible to close the channel sooner.
* true: timers are real events that keep the loop alive until they fire.
*/
public function __construct(
int $capacity = 0,
int $noProducerTimeout = 0,
int $noConsumerTimeout = 0,
bool $hardTimeouts = false,
) {}
/**
* Send a value into the channel (blocking).
*
* Suspends the current coroutine until the value
* is received (unbuffered) or buffered.
*
* @param Completable|null $cancellationToken Optional cancellation token (e.g. timeout(ms))
* @throws ChannelException if channel is closed
* @throws \Throwable if cancellation token fires
*/
public function send(mixed $value, ?Completable $cancellationToken = null): void {}
/**
* Try to send a value without blocking.
*
* @return bool true if sent successfully, false if channel is full or closed
*/
public function sendAsync(mixed $value): bool {}
/**
* Receive a value from the channel (blocking).
*
* Suspends the current coroutine until a value is available.
*
* @param Completable|null $cancellationToken Optional cancellation token (e.g. timeout(ms))
* @throws ChannelException if channel is closed and empty
* @throws \Throwable if cancellation token fires
*/
public function recv(?Completable $cancellationToken = null): mixed {}
/**
* Receive a value without blocking, returns Future.
*
* @return Future<mixed> Future that resolves to the received value
*/
public function recvAsync(): Future {}
/**
* Close the channel.
*
* After closing:
* - send() throws ChannelException
* - recv() drains remaining values, then throws ChannelException
* - All waiting coroutines are woken with ChannelException
*/
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 {}
/**
* Get iterator for foreach support.
*
* Allows: foreach ($channel as $value) { ... }
* Iteration stops when channel is closed and empty.
*/
public function getIterator(): \Iterator {}
}