@@ -303,7 +303,7 @@ Re-attach the data source after a previous `pause()`.
303
303
``` php
304
304
$stream->pause();
305
305
306
- $loop-> addTimer(1.0, function () use ($stream) {
306
+ Loop:: addTimer(1.0, function () use ($stream) {
307
307
$stream->resume();
308
308
});
309
309
```
@@ -737,7 +737,7 @@ stream in order to stop waiting for the stream to flush its final data.
737
737
738
738
``` php
739
739
$stream->end();
740
- $loop-> addTimer(1.0, function () use ($stream) {
740
+ Loop:: addTimer(1.0, function () use ($stream) {
741
741
$stream->close();
742
742
});
743
743
```
@@ -821,7 +821,7 @@ This can be used to represent a read-only resource like a file stream opened in
821
821
readable mode or a stream such as ` STDIN ` :
822
822
823
823
``` php
824
- $stream = new ReadableResourceStream(STDIN, $loop );
824
+ $stream = new ReadableResourceStream(STDIN);
825
825
$stream->on('data', function ($chunk) {
826
826
echo $chunk;
827
827
});
@@ -838,7 +838,7 @@ Otherwise, it will throw an `InvalidArgumentException`:
838
838
839
839
``` php
840
840
// throws InvalidArgumentException
841
- $stream = new ReadableResourceStream(false, $loop );
841
+ $stream = new ReadableResourceStream(false);
842
842
```
843
843
844
844
See also the [ ` DuplexResourceStream ` ] ( #readableresourcestream ) for read-and-write
@@ -851,14 +851,20 @@ If this fails, it will throw a `RuntimeException`:
851
851
852
852
``` php
853
853
// throws RuntimeException on Windows
854
- $stream = new ReadableResourceStream(STDIN, $loop );
854
+ $stream = new ReadableResourceStream(STDIN);
855
855
```
856
856
857
857
Once the constructor is called with a valid stream resource, this class will
858
858
take care of the underlying stream resource.
859
859
You SHOULD only use its public API and SHOULD NOT interfere with the underlying
860
860
stream resource manually.
861
861
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
+
862
868
This class takes an optional ` int|null $readChunkSize ` parameter that controls
863
869
the maximum buffer size in bytes to read at once from the stream.
864
870
You 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
874
880
mean it reached EOF.
875
881
876
882
``` php
877
- $stream = new ReadableResourceStream(STDIN, $loop , 8192);
883
+ $stream = new ReadableResourceStream(STDIN, null , 8192);
878
884
```
879
885
880
886
> PHP bug warning: If the PHP process has explicitly been started without a
@@ -883,6 +889,9 @@ $stream = new ReadableResourceStream(STDIN, $loop, 8192);
883
889
stream like ` php test.php < /dev/null ` instead of ` php test.php <&- ` .
884
890
See [ #81 ] ( https://github.com/reactphp/stream/issues/81 ) for more details.
885
891
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
+
886
895
### WritableResourceStream
887
896
888
897
The ` 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
892
901
writable mode or a stream such as ` STDOUT ` or ` STDERR ` :
893
902
894
903
``` php
895
- $stream = new WritableResourceStream(STDOUT, $loop );
904
+ $stream = new WritableResourceStream(STDOUT);
896
905
$stream->write('hello!');
897
906
$stream->end();
898
907
```
@@ -905,7 +914,7 @@ Otherwise, it will throw an `InvalidArgumentException`:
905
914
906
915
``` php
907
916
// throws InvalidArgumentException
908
- $stream = new WritableResourceStream(false, $loop );
917
+ $stream = new WritableResourceStream(false);
909
918
```
910
919
911
920
See also the [ ` DuplexResourceStream ` ] ( #readableresourcestream ) for read-and-write
@@ -918,7 +927,7 @@ If this fails, it will throw a `RuntimeException`:
918
927
919
928
``` php
920
929
// throws RuntimeException on Windows
921
- $stream = new WritableResourceStream(STDOUT, $loop );
930
+ $stream = new WritableResourceStream(STDOUT);
922
931
```
923
932
924
933
Once 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.
933
942
This buffer has a soft-limit applied which defines how much data it is willing
934
943
to accept before the caller SHOULD stop sending further data.
935
944
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
+
936
951
This class takes an optional ` int|null $writeBufferSoftLimit ` parameter that controls
937
952
this maximum buffer size in bytes.
938
953
You can use a ` null ` value here in order to apply its default value.
939
954
This value SHOULD NOT be changed unless you know what you're doing.
940
955
941
956
``` php
942
- $stream = new WritableResourceStream(STDOUT, $loop , 8192);
957
+ $stream = new WritableResourceStream(STDOUT, null , 8192);
943
958
```
944
959
945
960
This 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
954
969
underlying stream resource.
955
970
956
971
``` php
957
- $stream = new WritableResourceStream(STDOUT, $loop , null, 8192);
972
+ $stream = new WritableResourceStream(STDOUT, null , null, 8192);
958
973
```
959
974
960
975
See also [ ` write() ` ] ( #write ) for more details.
961
976
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
+
962
980
### DuplexResourceStream
963
981
964
982
The ` 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:
969
987
970
988
``` php
971
989
$conn = stream_socket_client('tcp://google.com:80');
972
- $stream = new DuplexResourceStream($conn, $loop );
990
+ $stream = new DuplexResourceStream($conn);
973
991
$stream->write('hello!');
974
992
$stream->end();
975
993
```
@@ -982,7 +1000,7 @@ Otherwise, it will throw an `InvalidArgumentException`:
982
1000
983
1001
``` php
984
1002
// throws InvalidArgumentException
985
- $stream = new DuplexResourceStream(false, $loop );
1003
+ $stream = new DuplexResourceStream(false);
986
1004
```
987
1005
988
1006
See also the [ ` ReadableResourceStream ` ] ( #readableresourcestream ) for read-only
@@ -996,14 +1014,20 @@ If this fails, it will throw a `RuntimeException`:
996
1014
997
1015
``` php
998
1016
// throws RuntimeException on Windows
999
- $stream = new DuplexResourceStream(STDOUT, $loop );
1017
+ $stream = new DuplexResourceStream(STDOUT);
1000
1018
```
1001
1019
1002
1020
Once the constructor is called with a valid stream resource, this class will
1003
1021
take care of the underlying stream resource.
1004
1022
You SHOULD only use its public API and SHOULD NOT interfere with the underlying
1005
1023
stream resource manually.
1006
1024
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
+
1007
1031
This class takes an optional ` int|null $readChunkSize ` parameter that controls
1008
1032
the maximum buffer size in bytes to read at once from the stream.
1009
1033
You can use a ` null ` value here in order to apply its default value.
@@ -1020,7 +1044,7 @@ mean it reached EOF.
1020
1044
1021
1045
``` php
1022
1046
$conn = stream_socket_client('tcp://google.com:80');
1023
- $stream = new DuplexResourceStream($conn, $loop , 8192);
1047
+ $stream = new DuplexResourceStream($conn, null , 8192);
1024
1048
```
1025
1049
1026
1050
Any ` 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
1040
1064
1041
1065
``` php
1042
1066
$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);
1045
1069
```
1046
1070
1047
1071
See also [ ` WritableResourceStream ` ] ( #writableresourcestream ) for more details.
1048
1072
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
+
1049
1076
### ThroughStream
1050
1077
1051
1078
The ` ThroughStream ` implements the
@@ -1123,8 +1150,8 @@ This is useful for some APIs which may require a single
1123
1150
more convenient to work with a single stream instance like this:
1124
1151
1125
1152
``` php
1126
- $stdin = new ReadableResourceStream(STDIN, $loop );
1127
- $stdout = new WritableResourceStream(STDOUT, $loop );
1153
+ $stdin = new ReadableResourceStream(STDIN);
1154
+ $stdout = new WritableResourceStream(STDOUT);
1128
1155
1129
1156
$stdio = new CompositeStream($stdin, $stdout);
1130
1157
@@ -1154,14 +1181,10 @@ The following example can be used to pipe the contents of a source file into
1154
1181
a destination file without having to ever read the whole file into memory:
1155
1182
1156
1183
``` 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'));
1161
1186
1162
1187
$source->pipe($dest);
1163
-
1164
- $loop->run();
1165
1188
```
1166
1189
1167
1190
> Note that this example uses ` fopen() ` for illustration purposes only.
0 commit comments