@@ -22,6 +22,7 @@ For the code of the current stable 0.4.x release, checkout the
22
22
* [ Install] ( #install )
23
23
* [ Tests] ( #tests )
24
24
* [ License] ( #license )
25
+ * [ More] ( #more )
25
26
26
27
## Quickstart example
27
28
@@ -291,6 +292,116 @@ echo 'a';
291
292
292
293
See also [ example #3 ] ( examples ) .
293
294
295
+ ### addReadStream()
296
+
297
+ > Advanced! Note that this low-level API is considered advanced usage.
298
+ Most use cases should probably use the higher-level
299
+ [ readable Stream API] ( https://github.com/reactphp/stream#readablestreaminterface )
300
+ instead.
301
+
302
+ The ` addReadStream(resource $stream, callable $callback): void ` method can be used to
303
+ register a listener to be notified when a stream is ready to read.
304
+
305
+ The first parameter MUST be a valid stream resource that supports
306
+ checking whether it is ready to read by this loop implementation.
307
+ A single stream resource MUST NOT be added more than once.
308
+ Instead, either call [ ` removeReadStream() ` ] ( #removereadstream ) first or
309
+ react to this event with a single listener and then dispatch from this
310
+ listener.
311
+
312
+ The listener callback function MUST be able to accept a single parameter,
313
+ the stream resource added by this method or you MAY use a function which
314
+ has no parameters at all.
315
+
316
+ The listener callback function MUST NOT throw an ` Exception ` .
317
+ The return value of the listener callback function will be ignored and has
318
+ no effect, so for performance reasons you're recommended to not return
319
+ any excessive data structures.
320
+
321
+ If you want to access any variables within your callback function, you
322
+ can bind arbitrary data to a callback closure like this:
323
+
324
+ ``` php
325
+ $loop->addReadStream($stream, function ($stream) use ($name) {
326
+ echo $name . ' said: ' . fread($stream);
327
+ });
328
+ ```
329
+
330
+ See also [ example #11 ] ( examples ) .
331
+
332
+ You can invoke [ ` removeReadStream() ` ] ( #removereadstream ) to remove the
333
+ read event listener for this stream.
334
+
335
+ The execution order of listeners when multiple streams become ready at
336
+ the same time is not guaranteed.
337
+
338
+ ### addWriteStream()
339
+
340
+ > Advanced! Note that this low-level API is considered advanced usage.
341
+ Most use cases should probably use the higher-level
342
+ [ writable Stream API] ( https://github.com/reactphp/stream#writablestreaminterface )
343
+ instead.
344
+
345
+ The ` addWriteStream(resource $stream, callable $callback): void ` method can be used to
346
+ register a listener to be notified when a stream is ready to write.
347
+
348
+ The first parameter MUST be a valid stream resource that supports
349
+ checking whether it is ready to write by this loop implementation.
350
+ A single stream resource MUST NOT be added more than once.
351
+ Instead, either call [ ` removeWriteStream() ` ] ( #removewritestream ) first or
352
+ react to this event with a single listener and then dispatch from this
353
+ listener.
354
+
355
+ The listener callback function MUST be able to accept a single parameter,
356
+ the stream resource added by this method or you MAY use a function which
357
+ has no parameters at all.
358
+
359
+ The listener callback function MUST NOT throw an ` Exception ` .
360
+ The return value of the listener callback function will be ignored and has
361
+ no effect, so for performance reasons you're recommended to not return
362
+ any excessive data structures.
363
+
364
+ If you want to access any variables within your callback function, you
365
+ can bind arbitrary data to a callback closure like this:
366
+
367
+ ``` php
368
+ $loop->addWriteStream($stream, function ($stream) use ($name) {
369
+ fwrite($stream, 'Hello ' . $name);
370
+ });
371
+ ```
372
+
373
+ See also [ example #12 ] ( examples ) .
374
+
375
+ You can invoke [ ` removeWriteStream() ` ] ( #removewritestream ) to remove the
376
+ write event listener for this stream.
377
+
378
+ The execution order of listeners when multiple streams become ready at
379
+ the same time is not guaranteed.
380
+
381
+ ### removeReadStream()
382
+
383
+ The ` removeReadStream(resource $stream): void ` method can be used to
384
+ remove the read event listener for the given stream.
385
+
386
+ Removing a stream from the loop that has already been removed or trying
387
+ to remove a stream that was never added or is invalid has no effect.
388
+
389
+ ### removeWriteStream()
390
+
391
+ The ` removeWriteStream(resource $stream): void ` method can be used to
392
+ remove the write event listener for the given stream.
393
+
394
+ Removing a stream from the loop that has already been removed or trying
395
+ to remove a stream that was never added or is invalid has no effect.
396
+
397
+ ### removeStream()
398
+
399
+ The ` removeStream(resource $stream): void ` method can be used to
400
+ remove all listeners for the given stream.
401
+
402
+ Removing a stream from the loop that has already been removed or trying
403
+ to remove a stream that was never added or is invalid has no effect.
404
+
294
405
## Install
295
406
296
407
The recommended way to install this library is [ through Composer] ( http://getcomposer.org ) .
@@ -320,3 +431,11 @@ $ php vendor/bin/phpunit
320
431
## License
321
432
322
433
MIT, see [ LICENSE file] ( LICENSE ) .
434
+
435
+ ## More
436
+
437
+ * See our [ Stream component] ( https://github.com/reactphp/stream ) for more
438
+ information on how streams are used in real-world applications.
439
+ * See our [ users wiki] ( https://github.com/reactphp/react/wiki/Users ) and the
440
+ [ dependents on Packagist] ( https://packagist.org/packages/react/event-loop/dependents )
441
+ for a list of packages that use the EventLoop in real-world applications.
0 commit comments