-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheventloop.stub.php
More file actions
223 lines (191 loc) · 6.21 KB
/
eventloop.stub.php
File metadata and controls
223 lines (191 loc) · 6.21 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
<?php
/**
* @generate-class-entries
*/
namespace EventLoop;
enum CallbackType {
case Defer;
case Delay;
case Repeat;
case Readable;
case Writable;
case Signal;
}
final class InvalidCallbackError extends \Error {
public readonly string $callbackId;
public function __construct(string $callbackId, string $message) {}
public function getCallbackId(): string {}
}
final class EventLoop {
/**
* Queue a microtask for immediate execution.
*
* @param \Closure(...):void $closure
* @param mixed ...$args
*/
public static function queue(\Closure $closure, mixed ...$args): void {}
/**
* Defer execution to the next iteration of the event loop.
*
* @param \Closure(string):void $closure Receives the callback identifier.
* @return string A unique callback identifier.
*/
public static function defer(\Closure $closure): string {}
/**
* Execute a callback after a delay in seconds.
*
* @param float $delay Delay in seconds.
* @param \Closure(string):void $closure Receives the callback identifier.
* @return string A unique callback identifier.
*/
public static function delay(float $delay, \Closure $closure): string {}
/**
* Execute a callback repeatedly at an interval in seconds.
*
* @param float $interval Interval in seconds.
* @param \Closure(string):void $closure Receives the callback identifier.
* @return string A unique callback identifier.
*/
public static function repeat(float $interval, \Closure $closure): string {}
/**
* Execute a callback when a stream becomes readable.
*
* @param resource $stream
* @param \Closure(string, resource):void $closure Receives the callback identifier and stream.
* @return string A unique callback identifier.
*/
public static function onReadable(mixed $stream, \Closure $closure): string {}
/**
* Execute a callback when a stream becomes writable.
*
* @param resource $stream
* @param \Closure(string, resource):void $closure Receives the callback identifier and stream.
* @return string A unique callback identifier.
*/
public static function onWritable(mixed $stream, \Closure $closure): string {}
/**
* Execute a callback when a signal is received.
*
* @param int $signal Signal number.
* @param \Closure(string, int):void $closure Receives the callback identifier and signal number.
* @return string A unique callback identifier.
*/
public static function onSignal(int $signal, \Closure $closure): string {}
/**
* Enable a callback by its identifier.
*
* @throws InvalidCallbackError If the callback identifier is invalid.
*/
public static function enable(string $callbackId): string {}
/**
* Disable a callback by its identifier.
*
* @throws InvalidCallbackError If the callback identifier is invalid.
*/
public static function disable(string $callbackId): string {}
/**
* Cancel a callback by its identifier. No-op if the identifier is invalid.
*/
public static function cancel(string $callbackId): void {}
/**
* Reference a callback so it keeps the event loop alive.
*
* @throws InvalidCallbackError If the callback identifier is invalid.
*/
public static function reference(string $callbackId): string {}
/**
* Unreference a callback so it no longer keeps the event loop alive.
*
* @throws InvalidCallbackError If the callback identifier is invalid.
*/
public static function unreference(string $callbackId): string {}
/**
* Check whether a callback is enabled.
*
* @throws InvalidCallbackError If the callback identifier is invalid.
*/
public static function isEnabled(string $callbackId): bool {}
/**
* Check whether a callback is referenced.
*
* @throws InvalidCallbackError If the callback identifier is invalid.
*/
public static function isReferenced(string $callbackId): bool {}
/**
* Get the type of a callback.
*
* @throws InvalidCallbackError If the callback identifier is invalid.
*/
public static function getType(string $callbackId): CallbackType {}
/**
* Get all registered callback identifiers.
*
* @return list<string>
*/
public static function getIdentifiers(): array {}
/**
* Run the event loop.
*
* @throws \Error If the event loop is already running.
*/
public static function run(): void {}
/**
* Stop the event loop.
*/
public static function stop(): void {}
/**
* Check if the event loop is running.
*/
public static function isRunning(): bool {}
/**
* Set the error handler for callback exceptions.
*
* @param null|\Closure(\Throwable):void $errorHandler
*/
public static function setErrorHandler(?\Closure $errorHandler): void {}
/**
* Get the current error handler.
*
* @return null|\Closure(\Throwable):void
*/
public static function getErrorHandler(): ?\Closure {}
/**
* Get a Suspension object for the current execution context.
* Only available when Fibers are enabled.
*/
#ifdef HAVE_FIBERS
public static function getSuspension(): Suspension {}
#endif
/**
* Get the name of the active I/O driver.
*/
public static function getDriver(): string {}
}
#ifdef HAVE_FIBERS
/**
* @template T
*/
final class Suspension {
/**
* Suspend the current fiber and return to the event loop.
*
* @return T
* @throws \Error If called outside of a fiber.
* @throws \Throwable Rethrown from a {@see throw()} call.
*/
public function suspend(): mixed {}
/**
* Resume the suspended fiber with a value.
*
* @param T $value
* @throws \Error If the suspension is not suspended or resume was already called.
*/
public function resume(mixed $value = null): void {}
/**
* Resume the suspended fiber by throwing an exception.
*
* @throws \Error If the suspension is not suspended or a resume/throw is already pending.
*/
public function throw(\Throwable $throwable): void {}
}
#endif