@@ -303,7 +303,7 @@ Re-attach the data source after a previous `pause()`.
303303``` php
304304$stream->pause();
305305
306- $loop-> addTimer(1.0, function () use ($stream) {
306+ Loop:: addTimer(1.0, function () use ($stream) {
307307 $stream->resume();
308308});
309309```
@@ -737,7 +737,7 @@ stream in order to stop waiting for the stream to flush its final data.
737737
738738``` php
739739$stream->end();
740- $loop-> addTimer(1.0, function () use ($stream) {
740+ Loop:: addTimer(1.0, function () use ($stream) {
741741 $stream->close();
742742});
743743```
@@ -821,7 +821,7 @@ This can be used to represent a read-only resource like a file stream opened in
821821readable mode or a stream such as ` STDIN ` :
822822
823823``` php
824- $stream = new ReadableResourceStream(STDIN, $loop );
824+ $stream = new ReadableResourceStream(STDIN);
825825$stream->on('data', function ($chunk) {
826826 echo $chunk;
827827});
@@ -838,7 +838,7 @@ Otherwise, it will throw an `InvalidArgumentException`:
838838
839839``` php
840840// throws InvalidArgumentException
841- $stream = new ReadableResourceStream(false, $loop );
841+ $stream = new ReadableResourceStream(false);
842842```
843843
844844See also the [ ` DuplexResourceStream ` ] ( #readableresourcestream ) for read-and-write
@@ -851,14 +851,20 @@ If this fails, it will throw a `RuntimeException`:
851851
852852``` php
853853// throws RuntimeException on Windows
854- $stream = new ReadableResourceStream(STDIN, $loop );
854+ $stream = new ReadableResourceStream(STDIN);
855855```
856856
857857Once the constructor is called with a valid stream resource, this class will
858858take care of the underlying stream resource.
859859You SHOULD only use its public API and SHOULD NOT interfere with the underlying
860860stream resource manually.
861861
862+ This class takes an optional ` LoopInterface|null $loop ` parameter that can be used to
863+ pass the event loop instance to use for this object. You can use a ` null ` value
864+ here in order to use the [ default loop] ( https://github.com/reactphp/event-loop#loop ) .
865+ This value SHOULD NOT be given unless you're sure you want to explicitly use a
866+ given event loop instance.
867+
862868This class takes an optional ` int|null $readChunkSize ` parameter that controls
863869the maximum buffer size in bytes to read at once from the stream.
864870You can use a ` null ` value here in order to apply its default value.
@@ -874,7 +880,7 @@ This should read until the stream resource is not readable anymore
874880mean it reached EOF.
875881
876882``` php
877- $stream = new ReadableResourceStream(STDIN, $loop , 8192);
883+ $stream = new ReadableResourceStream(STDIN, null , 8192);
878884```
879885
880886> PHP bug warning: If the PHP process has explicitly been started without a
@@ -883,6 +889,9 @@ $stream = new ReadableResourceStream(STDIN, $loop, 8192);
883889 stream like ` php test.php < /dev/null ` instead of ` php test.php <&- ` .
884890 See [ #81 ] ( https://github.com/reactphp/stream/issues/81 ) for more details.
885891
892+ > Changelog: As of v1.2.0 the ` $loop ` parameter can be omitted (or skipped with a
893+ ` null ` value) to use the [ default loop] ( https://github.com/reactphp/event-loop#loop ) .
894+
886895### WritableResourceStream
887896
888897The ` WritableResourceStream ` is a concrete implementation of the
@@ -892,7 +901,7 @@ This can be used to represent a write-only resource like a file stream opened in
892901writable mode or a stream such as ` STDOUT ` or ` STDERR ` :
893902
894903``` php
895- $stream = new WritableResourceStream(STDOUT, $loop );
904+ $stream = new WritableResourceStream(STDOUT);
896905$stream->write('hello!');
897906$stream->end();
898907```
@@ -905,7 +914,7 @@ Otherwise, it will throw an `InvalidArgumentException`:
905914
906915``` php
907916// throws InvalidArgumentException
908- $stream = new WritableResourceStream(false, $loop );
917+ $stream = new WritableResourceStream(false);
909918```
910919
911920See also the [ ` DuplexResourceStream ` ] ( #readableresourcestream ) for read-and-write
@@ -918,7 +927,7 @@ If this fails, it will throw a `RuntimeException`:
918927
919928``` php
920929// throws RuntimeException on Windows
921- $stream = new WritableResourceStream(STDOUT, $loop );
930+ $stream = new WritableResourceStream(STDOUT);
922931```
923932
924933Once the constructor is called with a valid stream resource, this class will
@@ -933,13 +942,19 @@ For this, it uses an in-memory buffer string to collect all outstanding writes.
933942This buffer has a soft-limit applied which defines how much data it is willing
934943to accept before the caller SHOULD stop sending further data.
935944
945+ This class takes an optional ` LoopInterface|null $loop ` parameter that can be used to
946+ pass the event loop instance to use for this object. You can use a ` null ` value
947+ here in order to use the [ default loop] ( https://github.com/reactphp/event-loop#loop ) .
948+ This value SHOULD NOT be given unless you're sure you want to explicitly use a
949+ given event loop instance.
950+
936951This class takes an optional ` int|null $writeBufferSoftLimit ` parameter that controls
937952this maximum buffer size in bytes.
938953You can use a ` null ` value here in order to apply its default value.
939954This value SHOULD NOT be changed unless you know what you're doing.
940955
941956``` php
942- $stream = new WritableResourceStream(STDOUT, $loop , 8192);
957+ $stream = new WritableResourceStream(STDOUT, null , 8192);
943958```
944959
945960This class takes an optional ` int|null $writeChunkSize ` parameter that controls
@@ -954,11 +969,14 @@ This can be `-1` which means "write everything available" to the
954969underlying stream resource.
955970
956971``` php
957- $stream = new WritableResourceStream(STDOUT, $loop , null, 8192);
972+ $stream = new WritableResourceStream(STDOUT, null , null, 8192);
958973```
959974
960975See also [ ` write() ` ] ( #write ) for more details.
961976
977+ > Changelog: As of v1.2.0 the ` $loop ` parameter can be omitted (or skipped with a
978+ ` null ` value) to use the [ default loop] ( https://github.com/reactphp/event-loop#loop ) .
979+
962980### DuplexResourceStream
963981
964982The ` DuplexResourceStream ` is a concrete implementation of the
@@ -969,7 +987,7 @@ in read and write mode mode or a stream such as a TCP/IP connection:
969987
970988``` php
971989$conn = stream_socket_client('tcp://google.com:80');
972- $stream = new DuplexResourceStream($conn, $loop );
990+ $stream = new DuplexResourceStream($conn);
973991$stream->write('hello!');
974992$stream->end();
975993```
@@ -982,7 +1000,7 @@ Otherwise, it will throw an `InvalidArgumentException`:
9821000
9831001``` php
9841002// throws InvalidArgumentException
985- $stream = new DuplexResourceStream(false, $loop );
1003+ $stream = new DuplexResourceStream(false);
9861004```
9871005
9881006See also the [ ` ReadableResourceStream ` ] ( #readableresourcestream ) for read-only
@@ -996,14 +1014,20 @@ If this fails, it will throw a `RuntimeException`:
9961014
9971015``` php
9981016// throws RuntimeException on Windows
999- $stream = new DuplexResourceStream(STDOUT, $loop );
1017+ $stream = new DuplexResourceStream(STDOUT);
10001018```
10011019
10021020Once the constructor is called with a valid stream resource, this class will
10031021take care of the underlying stream resource.
10041022You SHOULD only use its public API and SHOULD NOT interfere with the underlying
10051023stream resource manually.
10061024
1025+ This class takes an optional ` LoopInterface|null $loop ` parameter that can be used to
1026+ pass the event loop instance to use for this object. You can use a ` null ` value
1027+ here in order to use the [ default loop] ( https://github.com/reactphp/event-loop#loop ) .
1028+ This value SHOULD NOT be given unless you're sure you want to explicitly use a
1029+ given event loop instance.
1030+
10071031This class takes an optional ` int|null $readChunkSize ` parameter that controls
10081032the maximum buffer size in bytes to read at once from the stream.
10091033You can use a ` null ` value here in order to apply its default value.
@@ -1020,7 +1044,7 @@ mean it reached EOF.
10201044
10211045``` php
10221046$conn = stream_socket_client('tcp://google.com:80');
1023- $stream = new DuplexResourceStream($conn, $loop , 8192);
1047+ $stream = new DuplexResourceStream($conn, null , 8192);
10241048```
10251049
10261050Any ` write() ` calls to this class will not be performed instantly, but will
@@ -1040,12 +1064,15 @@ If you want to change the write buffer soft limit, you can pass an instance of
10401064
10411065``` php
10421066$conn = stream_socket_client('tcp://google.com:80');
1043- $buffer = new WritableResourceStream($conn, $loop , 8192);
1044- $stream = new DuplexResourceStream($conn, $loop , null, $buffer);
1067+ $buffer = new WritableResourceStream($conn, null , 8192);
1068+ $stream = new DuplexResourceStream($conn, null , null, $buffer);
10451069```
10461070
10471071See also [ ` WritableResourceStream ` ] ( #writableresourcestream ) for more details.
10481072
1073+ > Changelog: As of v1.2.0 the ` $loop ` parameter can be omitted (or skipped with a
1074+ ` null ` value) to use the [ default loop] ( https://github.com/reactphp/event-loop#loop ) .
1075+
10491076### ThroughStream
10501077
10511078The ` ThroughStream ` implements the
@@ -1123,8 +1150,8 @@ This is useful for some APIs which may require a single
11231150more convenient to work with a single stream instance like this:
11241151
11251152``` php
1126- $stdin = new ReadableResourceStream(STDIN, $loop );
1127- $stdout = new WritableResourceStream(STDOUT, $loop );
1153+ $stdin = new ReadableResourceStream(STDIN);
1154+ $stdout = new WritableResourceStream(STDOUT);
11281155
11291156$stdio = new CompositeStream($stdin, $stdout);
11301157
@@ -1154,14 +1181,10 @@ The following example can be used to pipe the contents of a source file into
11541181a destination file without having to ever read the whole file into memory:
11551182
11561183``` php
1157- $loop = new React\EventLoop\StreamSelectLoop;
1158-
1159- $source = new React\Stream\ReadableResourceStream(fopen('source.txt', 'r'), $loop);
1160- $dest = new React\Stream\WritableResourceStream(fopen('destination.txt', 'w'), $loop);
1184+ $source = new React\Stream\ReadableResourceStream(fopen('source.txt', 'r'));
1185+ $dest = new React\Stream\WritableResourceStream(fopen('destination.txt', 'w'));
11611186
11621187$source->pipe($dest);
1163-
1164- $loop->run();
11651188```
11661189
11671190> Note that this example uses ` fopen() ` for illustration purposes only.
0 commit comments