@@ -291,6 +291,83 @@ echo 'a';
291291
292292See also [ example #3 ] ( examples ) .
293293
294+ ### addReadStream()
295+
296+ The ` addReadStream(resource $stream, callable $callback): void ` method can be used to
297+ register a listener to be notified when a stream is ready to read.
298+
299+ The listener callback function MUST be able to accept a single parameter,
300+ the stream resource added by this method or you MAY use a function which
301+ has no parameters at all.
302+
303+ The listener callback function MUST NOT throw an ` Exception ` .
304+ The return value of the listener callback function will be ignored and has
305+ no effect, so for performance reasons you're recommended to not return
306+ any excessive data structures.
307+
308+ If you want to access any variables within your callback function, you
309+ can bind arbitrary data to a callback closure like this:
310+
311+ ``` php
312+ $loop->addReadStream($stream, function ($stream) use ($name) {
313+ echo $name . ' said: ' . fread($stream);
314+ });
315+ ```
316+
317+ See also [ example #11 ] ( examples ) .
318+
319+ You can invoke [ ` removeReadStream() ` ] ( #removereadstream ) to remove the
320+ read event listener for this stream.
321+
322+ The execution order of listeners when multiple streams become ready at
323+ the same time is not guaranteed.
324+
325+ ### addWriteStream()
326+
327+ The ` addWriteStream(resource $stream, callable $callback): void ` method can be used to
328+ register a listener to be notified when a stream is ready to write.
329+
330+ The listener callback function MUST be able to accept a single parameter,
331+ the stream resource added by this method or you MAY use a function which
332+ has no parameters at all.
333+
334+ The listener callback function MUST NOT throw an ` Exception ` .
335+ The return value of the listener callback function will be ignored and has
336+ no effect, so for performance reasons you're recommended to not return
337+ any excessive data structures.
338+
339+ If you want to access any variables within your callback function, you
340+ can bind arbitrary data to a callback closure like this:
341+
342+ ``` php
343+ $loop->addWriteStream($stream, function ($stream) use ($name) {
344+ fwrite($stream, 'Hello ' . $name);
345+ });
346+ ```
347+
348+ See also [ example #12 ] ( examples ) .
349+
350+ You can invoke [ ` removeWriteStream() ` ] ( #removewritestream ) to remove the
351+ write event listener for this stream.
352+
353+ The execution order of listeners when multiple streams become ready at
354+ the same time is not guaranteed.
355+
356+ ### removeReadStream()
357+
358+ The ` removeReadStream(resource $stream): void ` method can be used to
359+ remove the read event listener for the given stream.
360+
361+ ### removeWriteStream()
362+
363+ The ` removeWriteStream(resource $stream): void ` method can be used to
364+ remove the write event listener for the given stream.
365+
366+ ### removeStream()
367+
368+ The ` removeStream(resource $stream): void ` method can be used to
369+ remove all listeners for the given stream.
370+
294371## Install
295372
296373The recommended way to install this library is [ through Composer] ( http://getcomposer.org ) .
0 commit comments