@@ -129,10 +129,14 @@ public static function stop()
129
129
/**
130
130
* Defer the execution of a callback.
131
131
*
132
- * @param callable(string $watcherId, mixed $data) $callback The callback to defer.
132
+ * The deferred callable MUST be executed in the next tick of the event loop and before any other type of watcher.
133
+ * Order of enabling MUST be preserved when executing the callbacks.
134
+ *
135
+ * @param callable(string $watcherId, mixed $data) $callback The callback to defer. The `$watcherId` will be
136
+ * invalidated before the callback call.
133
137
* @param mixed $data Arbitrary data given to the callback function as the `$data` parameter.
134
138
*
135
- * @return string An identifier that can be used to cancel, enable or disable the watcher.
139
+ * @return string An unique identifier that can be used to cancel, enable or disable the watcher.
136
140
*/
137
141
public static function defer (callable $ callback , $ data = null )
138
142
{
@@ -143,13 +147,15 @@ public static function defer(callable $callback, $data = null)
143
147
/**
144
148
* Delay the execution of a callback.
145
149
*
146
- * The delay is a minimum and approximate, accuracy is not guaranteed.
150
+ * The delay is a minimum and approximate, accuracy is not guaranteed. Order of calls MUST be determined by which
151
+ * timers expire first, but timers with the same expiration time MAY be executed in any order.
147
152
*
148
- * @param int $time The amount of time, in milliseconds, to delay the execution for.
149
- * @param callable(string $watcherId, mixed $data) $callback The callback to delay.
153
+ * @param int $delay The amount of time, in milliseconds, to delay the execution for.
154
+ * @param callable(string $watcherId, mixed $data) $callback The callback to delay. The `$watcherId` will be
155
+ * invalidated before the callback call.
150
156
* @param mixed $data Arbitrary data given to the callback function as the `$data` parameter.
151
157
*
152
- * @return string An identifier that can be used to cancel, enable or disable the watcher.
158
+ * @return string An unique identifier that can be used to cancel, enable or disable the watcher.
153
159
*/
154
160
public static function delay ($ time , callable $ callback , $ data = null )
155
161
{
@@ -160,14 +166,15 @@ public static function delay($time, callable $callback, $data = null)
160
166
/**
161
167
* Repeatedly execute a callback.
162
168
*
163
- * The interval between executions is a minimum and approximate, accuracy is not guaranteed.
169
+ * The interval between executions is a minimum and approximate, accuracy is not guaranteed. Order of calls MUST be
170
+ * determined by which timers expire first, but timers with the same expiration time MAY be executed in any order.
164
171
* The first execution is scheduled after the first interval period.
165
172
*
166
173
* @param int $interval The time interval, in milliseconds, to wait between executions.
167
174
* @param callable(string $watcherId, mixed $data) $callback The callback to repeat.
168
175
* @param mixed $data Arbitrary data given to the callback function as the `$data` parameter.
169
176
*
170
- * @return string An identifier that can be used to cancel, enable or disable the watcher.
177
+ * @return string An unique identifier that can be used to cancel, enable or disable the watcher.
171
178
*/
172
179
public static function repeat ($ interval , callable $ callback , $ data = null )
173
180
{
@@ -178,11 +185,18 @@ public static function repeat($interval, callable $callback, $data = null)
178
185
/**
179
186
* Execute a callback when a stream resource becomes readable or is closed for reading.
180
187
*
188
+ * Warning: Closing resources locally, e.g. with `fclose`, might not invoke the callback. Be sure to `cancel` the
189
+ * watcher when closing the resource locally. Drivers MAY choose to notify the user if there are watchers on invalid
190
+ * resources, but are not required to, due to the high performance impact. Watchers on closed resources are
191
+ * therefore undefined behavior.
192
+ *
193
+ * Multiple watchers on the same stream MAY be executed in any order.
194
+ *
181
195
* @param resource $stream The stream to monitor.
182
196
* @param callable(string $watcherId, resource $stream, mixed $data) $callback The callback to execute.
183
197
* @param mixed $data Arbitrary data given to the callback function as the `$data` parameter.
184
198
*
185
- * @return string An identifier that can be used to cancel, enable or disable the watcher.
199
+ * @return string An unique identifier that can be used to cancel, enable or disable the watcher.
186
200
*/
187
201
public static function onReadable ($ stream , callable $ callback , $ data = null )
188
202
{
@@ -193,11 +207,18 @@ public static function onReadable($stream, callable $callback, $data = null)
193
207
/**
194
208
* Execute a callback when a stream resource becomes writable or is closed for writing.
195
209
*
210
+ * Warning: Closing resources locally, e.g. with `fclose`, might not invoke the callback. Be sure to `cancel` the
211
+ * watcher when closing the resource locally. Drivers MAY choose to notify the user if there are watchers on invalid
212
+ * resources, but are not required to, due to the high performance impact. Watchers on closed resources are
213
+ * therefore undefined behavior.
214
+ *
215
+ * Multiple watchers on the same stream MAY be executed in any order.
216
+ *
196
217
* @param resource $stream The stream to monitor.
197
218
* @param callable(string $watcherId, resource $stream, mixed $data) $callback The callback to execute.
198
219
* @param mixed $data Arbitrary data given to the callback function as the `$data` parameter.
199
220
*
200
- * @return string An identifier that can be used to cancel, enable or disable the watcher.
221
+ * @return string An unique identifier that can be used to cancel, enable or disable the watcher.
201
222
*/
202
223
public static function onWritable ($ stream , callable $ callback , $ data = null )
203
224
{
@@ -208,16 +229,19 @@ public static function onWritable($stream, callable $callback, $data = null)
208
229
/**
209
230
* Execute a callback when a signal is received.
210
231
*
211
- * WARNING: Installing a handler on the same signal on different scopes of event loop execution is
212
- * undefined behavior and may break things arbitrarily.
232
+ * Warning: Installing the same signal on different instances of this interface is deemed undefined behavior.
233
+ * Implementations MAY try to detect this, if possible, but are not required to. This is due to technical
234
+ * limitations of the signals being registered globally per process.
235
+ *
236
+ * Multiple watchers on the same signal MAY be executed in any order.
213
237
*
214
238
* @param int $signo The signal number to monitor.
215
239
* @param callable(string $watcherId, int $signo, mixed $data) $callback The callback to execute.
216
- * @param mixed $data Arbitrary data given to the callback function as the ` $data` parameter.
240
+ * @param mixed $data Arbitrary data given to the callback function as the $data parameter.
217
241
*
218
- * @return string An identifier that can be used to cancel, enable or disable the watcher.
242
+ * @return string An unique identifier that can be used to cancel, enable or disable the watcher.
219
243
*
220
- * @throws UnsupportedFeatureException Thrown if signal handling is not supported.
244
+ * @throws UnsupportedFeatureException If signal handling is not supported.
221
245
*/
222
246
public static function onSignal ($ signo , callable $ callback , $ data = null )
223
247
{
@@ -228,11 +252,15 @@ public static function onSignal($signo, callable $callback, $data = null)
228
252
/**
229
253
* Enable a watcher.
230
254
*
255
+ * Watchers (enabling or new watchers) MUST immediately be marked as enabled, but only be activated (i.e. callbacks
256
+ * can be called) right before the next tick. Callbacks of watchers MUST not be called in the tick they were
257
+ * enabled.
258
+ *
231
259
* @param string $watcherId The watcher identifier.
232
260
*
233
261
* @return void
234
262
*
235
- * @throws InvalidWatcherException Thrown if the watcher identifier is invalid.
263
+ * @throws InvalidWatcherException If the watcher identifier is invalid.
236
264
*/
237
265
public static function enable ($ watcherId )
238
266
{
@@ -243,6 +271,9 @@ public static function enable($watcherId)
243
271
/**
244
272
* Disable a watcher.
245
273
*
274
+ * Disabling a watcher MUST NOT invalidate the watcher. Calling this function MUST NOT fail, even if passed an
275
+ * invalid watcher.
276
+ *
246
277
* @param string $watcherId The watcher identifier.
247
278
*
248
279
* @return void
@@ -256,8 +287,8 @@ public static function disable($watcherId)
256
287
/**
257
288
* Cancel a watcher.
258
289
*
259
- * This will detatch the event loop from all resources that are associated to the watcher. After this
260
- * operation the watcher is permanently invalid.
290
+ * This will detatch the event loop from all resources that are associated to the watcher. After this operation the
291
+ * watcher is permanently invalid. Calling this function MUST NOT fail, even if passed an invalid watcher .
261
292
*
262
293
* @param string $watcherId The watcher identifier.
263
294
*
@@ -272,8 +303,8 @@ public static function cancel($watcherId)
272
303
/**
273
304
* Reference a watcher.
274
305
*
275
- * This will keep the event loop alive whilst the watcher is still being monitored. Watchers have this state
276
- * by default.
306
+ * This will keep the event loop alive whilst the watcher is still being monitored. Watchers have this state by
307
+ * default.
277
308
*
278
309
* @param string $watcherId The watcher identifier.
279
310
*
@@ -290,8 +321,8 @@ public static function reference($watcherId)
290
321
/**
291
322
* Unreference a watcher.
292
323
*
293
- * The event loop should exit the run method when only unreferenced watchers are still being monitored.
294
- * Watchers are all referenced by default.
324
+ * The event loop should exit the run method when only unreferenced watchers are still being monitored. Watchers
325
+ * are all referenced by default.
295
326
*
296
327
* @param string $watcherId The watcher identifier.
297
328
*
@@ -309,8 +340,7 @@ public static function unreference($watcherId)
309
340
* Stores information in the loop bound registry.
310
341
*
311
342
* This can be used to store loop bound information. Stored information is package private. Packages MUST NOT
312
- * retrieve the stored state of other packages. Packages MUST use the following prefix to keys:
313
- * `vendor.package.`
343
+ * retrieve the stored state of other packages. Packages MUST use the following prefix for keys: `vendor.package.`
314
344
*
315
345
* @param string $key The namespaced storage key.
316
346
* @param mixed $value The value to be stored.
@@ -326,12 +356,12 @@ public static function setState($key, $value)
326
356
/**
327
357
* Gets information stored bound to the loop.
328
358
*
329
- * Stored information is package private. Packages MUST NOT retrieve the stored state of other packages.
330
- * Packages MUST use the following prefix to keys: `vendor.package.`
359
+ * Stored information is package private. Packages MUST NOT retrieve the stored state of other packages. Packages
360
+ * MUST use the following prefix for keys: `vendor.package.`
331
361
*
332
362
* @param string $key The namespaced storage key.
333
363
*
334
- * @return mixed previously stored value or null if it doesn't exist
364
+ * @return mixed The previously stored value or ` null` if it doesn't exist.
335
365
*/
336
366
public static function getState ($ key )
337
367
{
0 commit comments