@@ -178,11 +178,18 @@ public static function repeat($interval, callable $callback, $data = null)
178
178
/**
179
179
* Execute a callback when a stream resource becomes readable or is closed for reading.
180
180
*
181
+ * Warning: Closing resources locally, e.g. with `fclose`, might not invoke the callback. Be sure to `cancel` the
182
+ * watcher when closing the resource locally. Drivers might choose to notify the user in a debug mode if there are
183
+ * watchers on invalid resources, but are not required to, due to the high performance impact. Watchers on closed
184
+ * resources are therefore undefined behavior.
185
+ *
186
+ * Multiple watchers on the same stream may be executed in any order.
187
+ *
181
188
* @param resource $stream The stream to monitor.
182
189
* @param callable(string $watcherId, resource $stream, mixed $data) $callback The callback to execute.
183
190
* @param mixed $data Arbitrary data given to the callback function as the `$data` parameter.
184
191
*
185
- * @return string An identifier that can be used to cancel, enable or disable the watcher.
192
+ * @return string An unique identifier that can be used to cancel, enable or disable the watcher.
186
193
*/
187
194
public static function onReadable ($ stream , callable $ callback , $ data = null )
188
195
{
@@ -193,11 +200,18 @@ public static function onReadable($stream, callable $callback, $data = null)
193
200
/**
194
201
* Execute a callback when a stream resource becomes writable or is closed for writing.
195
202
*
203
+ * Warning: Closing resources locally, e.g. with `fclose`, might not invoke the callback. Be sure to `cancel` the
204
+ * watcher when closing the resource locally. Drivers might choose to notify the user in a debug mode if there are
205
+ * watchers on invalid resources, but are not required to, due to the high performance impact. Watchers on closed
206
+ * resources are therefore undefined behavior.
207
+ *
208
+ * Multiple watchers on the same stream may be executed in any order.
209
+ *
196
210
* @param resource $stream The stream to monitor.
197
211
* @param callable(string $watcherId, resource $stream, mixed $data) $callback The callback to execute.
198
212
* @param mixed $data Arbitrary data given to the callback function as the `$data` parameter.
199
213
*
200
- * @return string An identifier that can be used to cancel, enable or disable the watcher.
214
+ * @return string An unique identifier that can be used to cancel, enable or disable the watcher.
201
215
*/
202
216
public static function onWritable ($ stream , callable $ callback , $ data = null )
203
217
{
@@ -208,16 +222,19 @@ public static function onWritable($stream, callable $callback, $data = null)
208
222
/**
209
223
* Execute a callback when a signal is received.
210
224
*
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.
225
+ * Warning: Installing the same signal on different instances of this interface is deemed undefined behavior.
226
+ * Implementations may try to detect this, if possible, but are not required to. This is due to technical
227
+ * limitations of the signals being registered globally per process.
228
+ *
229
+ * Multiple watchers on the same signal may be executed in any order.
213
230
*
214
231
* @param int $signo The signal number to monitor.
215
232
* @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.
233
+ * @param mixed $data Arbitrary data given to the callback function as the $data parameter.
217
234
*
218
- * @return string An identifier that can be used to cancel, enable or disable the watcher.
235
+ * @return string An unique identifier that can be used to cancel, enable or disable the watcher.
219
236
*
220
- * @throws UnsupportedFeatureException Thrown if signal handling is not supported.
237
+ * @throws UnsupportedFeatureException If signal handling is not supported.
221
238
*/
222
239
public static function onSignal ($ signo , callable $ callback , $ data = null )
223
240
{
@@ -228,11 +245,15 @@ public static function onSignal($signo, callable $callback, $data = null)
228
245
/**
229
246
* Enable a watcher.
230
247
*
248
+ * Watchers (enabling or new watchers) MUST immediately be marked as enabled, but only be activated (i.e. callbacks
249
+ * can be called) right before the next tick. Callbacks of watchers MUST not be called in the tick they were
250
+ * enabled.
251
+ *
231
252
* @param string $watcherId The watcher identifier.
232
253
*
233
254
* @return void
234
255
*
235
- * @throws InvalidWatcherException Thrown if the watcher identifier is invalid.
256
+ * @throws InvalidWatcherException If the watcher identifier is invalid.
236
257
*/
237
258
public static function enable ($ watcherId )
238
259
{
@@ -243,6 +264,9 @@ public static function enable($watcherId)
243
264
/**
244
265
* Disable a watcher.
245
266
*
267
+ * Disabling a watcher MUST NOT invalidate the watcher. Calling this function MUST NOT fail, even if passed an
268
+ * invalid watcher.
269
+ *
246
270
* @param string $watcherId The watcher identifier.
247
271
*
248
272
* @return void
@@ -256,8 +280,8 @@ public static function disable($watcherId)
256
280
/**
257
281
* Cancel a watcher.
258
282
*
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.
283
+ * This will detatch the event loop from all resources that are associated to the watcher. After this operation the
284
+ * watcher is permanently invalid. Calling this function MUST NOT fail, even if passed an invalid watcher .
261
285
*
262
286
* @param string $watcherId The watcher identifier.
263
287
*
@@ -272,8 +296,8 @@ public static function cancel($watcherId)
272
296
/**
273
297
* Reference a watcher.
274
298
*
275
- * This will keep the event loop alive whilst the watcher is still being monitored. Watchers have this state
276
- * by default.
299
+ * This will keep the event loop alive whilst the watcher is still being monitored. Watchers have this state by
300
+ * default.
277
301
*
278
302
* @param string $watcherId The watcher identifier.
279
303
*
@@ -290,8 +314,8 @@ public static function reference($watcherId)
290
314
/**
291
315
* Unreference a watcher.
292
316
*
293
- * The event loop should exit the run method when only unreferenced watchers are still being monitored.
294
- * Watchers are all referenced by default.
317
+ * The event loop should exit the run method when only unreferenced watchers are still being monitored. Watchers
318
+ * are all referenced by default.
295
319
*
296
320
* @param string $watcherId The watcher identifier.
297
321
*
@@ -309,8 +333,7 @@ public static function unreference($watcherId)
309
333
* Stores information in the loop bound registry.
310
334
*
311
335
* 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.`
336
+ * retrieve the stored state of other packages. Packages MUST use the following prefix for keys: `vendor.package.`
314
337
*
315
338
* @param string $key The namespaced storage key.
316
339
* @param mixed $value The value to be stored.
@@ -326,12 +349,12 @@ public static function setState($key, $value)
326
349
/**
327
350
* Gets information stored bound to the loop.
328
351
*
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.`
352
+ * Stored information is package private. Packages MUST NOT retrieve the stored state of other packages. Packages
353
+ * MUST use the following prefix for keys: `vendor.package.`
331
354
*
332
355
* @param string $key The namespaced storage key.
333
356
*
334
- * @return mixed previously stored value or null if it doesn't exist
357
+ * @return mixed The previously stored value or ` null` if it doesn't exist.
335
358
*/
336
359
public static function getState ($ key )
337
360
{
0 commit comments