-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathasync.stub.php
More file actions
238 lines (195 loc) · 5.78 KB
/
async.stub.php
File metadata and controls
238 lines (195 loc) · 5.78 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<?php
/** @generate-class-entries */
namespace Async;
interface Awaitable {}
interface Completable extends Awaitable {
public function cancel(?AsyncCancellation $cancellation = null): void;
public function isCompleted(): bool;
public function isCancelled(): bool;
}
final class Timeout implements Completable
{
private function __construct() {}
public function cancel(?AsyncCancellation $cancellation = null): void {}
public function isCompleted(): bool {}
public function isCancelled(): bool {}
}
/**
* Returns the current Coroutine.
*
* @return Coroutine
*/
function spawn(callable $task, mixed ... $args): Coroutine {}
/**
* Returns the current Coroutine.
*
* @return Coroutine
*/
function spawn_with(ScopeProvider $provider, callable $task, mixed ... $args): Coroutine {}
/**
* Suspends the execution of a Coroutine until the Scheduler takes control.
*/
function suspend(): void {}
/**
* Execute the provided closure in non-cancellable mode.
*/
function protect(\Closure $closure): mixed {}
function await(Completable $awaitable, ?Completable $cancellation = null): mixed {}
function await_any_or_fail(iterable $triggers, ?Awaitable $cancellation = null): mixed {}
function await_first_success(iterable $triggers, ?Awaitable $cancellation = null): mixed {}
function await_all_or_fail(iterable $triggers, ?Awaitable $cancellation = null, bool $preserveKeyOrder = true): array {}
function await_all(iterable $triggers, ?Awaitable $cancellation = null, bool $preserveKeyOrder = true, bool $fillNull = false): array {}
function await_any_of_or_fail(int $count, iterable $triggers, ?Awaitable $cancellation = null, bool $preserveKeyOrder = true): array {}
function await_any_of(int $count, iterable $triggers, ?Awaitable $cancellation = null, bool $preserveKeyOrder = true, bool $fillNull = false): array {}
function delay(int $ms): void {}
function timeout(int $ms): Awaitable {}
function current_context(): Context {}
function coroutine_context(): Context {}
/**
* Returns the current coroutine.
*/
function current_coroutine(): Coroutine {}
/**
* Adds a finally handler for the current coroutine.
*/
//function finally(\Closure $callback): void {}
/**
* Returns the root Scope.
*/
function root_context(): Context {}
/**
* Returns the list of all coroutines
*
* @return Coroutine[]
*/
function get_coroutines(): array {}
/**
* Iterates over an iterable, calling the callback for each element.
* The callback receives (value, key) and may return false to stop iteration.
* Blocks the current coroutine until all iterations complete.
*
* If cancelPending is true (default), coroutines spawned inside the callback
* will be cancelled when the iteration finishes. If false, iterate() will
* wait for all spawned coroutines to complete before returning.
*/
function iterate(iterable $iterable, callable $callback, int $concurrency = 0, bool $cancelPending = true): void {}
/**
* Start the graceful shutdown of the Scheduler.
*/
function graceful_shutdown(?AsyncCancellation $cancellationError = null): void {}
/**
* Execute an external program.
* @return Future<array{string, int}>
*/
/*
function exec(
string $command,
int $timeout = 0,
?string $cwd = null,
?array $env = null,
bool $returnAll = false
): Future {}
*/
/**
* OS signal identifiers.
*/
enum Signal: int
{
case SIGHUP = 1;
case SIGINT = 2;
case SIGQUIT = 3;
case SIGILL = 4;
case SIGABRT = 6;
case SIGFPE = 8;
case SIGKILL = 9;
case SIGUSR1 = 10;
case SIGSEGV = 11;
case SIGUSR2 = 12;
case SIGTERM = 15;
case SIGBREAK = 21;
case SIGABRT2 = 22;
case SIGWINCH = 28;
}
/**
* Wait for an OS signal.
* Returns a Future that resolves with the Signal enum value when the signal is received.
*
* @return Future<Signal>
*/
function signal(Signal $signal, ?Completable $cancellation = null): Future {}
/**
* Circuit breaker states.
*/
enum CircuitBreakerState
{
/**
* Service is working normally.
* All requests are allowed through.
*/
case ACTIVE;
/**
* Service is unavailable.
* All requests are rejected immediately.
*/
case INACTIVE;
/**
* Testing if service has recovered.
* Limited requests are allowed through.
*/
case RECOVERING;
}
/**
* Circuit breaker state machine.
*
* Manages state transitions for service availability.
* This interface defines HOW to transition between states.
* Use CircuitBreakerStrategy to define WHEN to transition.
*/
interface CircuitBreaker
{
/**
* Get current state.
*/
public function getState(): CircuitBreakerState;
/**
* Transition to ACTIVE state.
*/
public function activate(): void;
/**
* Transition to INACTIVE state.
*/
public function deactivate(): void;
/**
* Transition to RECOVERING state.
*/
public function recover(): void;
}
/**
* Circuit breaker strategy interface.
*
* Defines WHEN to transition between circuit breaker states.
* Implement this interface to create custom failure detection logic.
*/
interface CircuitBreakerStrategy
{
/**
* Called when an operation succeeds.
*
* @param mixed $source The object reporting the event (e.g., Pool)
*/
public function reportSuccess(mixed $source): void;
/**
* Called when an operation fails.
*
* @param mixed $source The object reporting the event (e.g., Pool)
* @param \Throwable $error The error that occurred
*/
public function reportFailure(mixed $source, \Throwable $error): void;
/**
* Check if circuit should attempt recovery.
*
* Called periodically when circuit is INACTIVE to determine
* if it should transition to RECOVERING state.
*/
public function shouldRecover(): bool;
}