@@ -22,18 +22,26 @@ for [ReactPHP](https://reactphp.org/).
2222This lightweight library consists only of a few simple functions.
2323All functions reside under the ` React\Promise\Stream ` namespace.
2424
25- The below examples assume you use an import statement similar to this:
25+ The below examples assume refer to them with their fully-qualified names like this:
2626
2727``` php
28- use React\Promise\Stream;
28+ React\Promise\Stream\buffer(…);
29+ ```
2930
30- Stream\buffer(…);
31+ As of PHP 5.6+ you can also import each required function into your code like this:
32+
33+ ``` php
34+ use function React\Promise\Stream\buffer;
35+
36+ buffer(…);
3137```
3238
33- Alternatively, you can also refer to them with their fully-qualified name :
39+ Alternatively, you can also use an import statement similar to this :
3440
3541``` php
36- \React\Promise\Stream\buffer(…);
42+ use React\Promise\Stream;
43+
44+ Stream\buffer(…);
3745```
3846
3947### buffer()
@@ -44,7 +52,7 @@ create a `Promise` which resolves with the stream data buffer.
4452``` php
4553$stream = accessSomeJsonStream();
4654
47- Stream\buffer($stream)->then(function ($contents) {
55+ React\Promise\ Stream\buffer($stream)->then(function ($contents) {
4856 var_dump(json_decode($contents));
4957});
5058```
@@ -64,7 +72,7 @@ will be rejected with an `\OverflowException`.
6472``` php
6573$stream = accessSomeToLargeStream();
6674
67- Stream\buffer($stream, 1024)->then(function ($contents) {
75+ React\Promise\ Stream\buffer($stream, 1024)->then(function ($contents) {
6876 var_dump(json_decode($contents));
6977}, function ($error) {
7078 // Reaching here when the stream buffer goes above the max size,
@@ -81,7 +89,7 @@ create a `Promise` which resolves once the given event triggers for the first ti
8189``` php
8290$stream = accessSomeJsonStream();
8391
84- Stream\first($stream)->then(function ($chunk) {
92+ React\Promise\ Stream\first($stream)->then(function ($chunk) {
8593 echo 'The first chunk arrived: ' . $chunk;
8694});
8795```
@@ -109,7 +117,7 @@ create a `Promise` which resolves with an array of all the event data.
109117``` php
110118$stream = accessSomeJsonStream();
111119
112- Stream\all($stream)->then(function ($chunks) {
120+ React\Promise\ Stream\all($stream)->then(function ($chunks) {
113121 echo 'The stream consists of ' . count($chunks) . ' chunk(s)';
114122});
115123```
@@ -141,7 +149,7 @@ be piped to the output stream.
141149//$promise = someFunctionWhichResolvesWithAStream();
142150$promise = startDownloadStream($uri);
143151
144- $stream = Stream\unwrapReadable($promise);
152+ $stream = React\Promise\ Stream\unwrapReadable($promise);
145153
146154$stream->on('data', function ($data) {
147155 echo $data;
@@ -159,7 +167,7 @@ an `error` event and close:
159167``` php
160168$promise = startDownloadStream($invalidUri);
161169
162- $stream = Stream\unwrapReadable($promise);
170+ $stream = React\Promise\ Stream\unwrapReadable($promise);
163171
164172$stream->on('error', function (Exception $error) {
165173 echo 'Error: ' . $error->getMessage();
@@ -178,7 +186,7 @@ You can `close()` the resulting stream at any time, which will either try to
178186``` php
179187$promise = startDownloadStream($uri);
180188
181- $stream = Stream\unwrapReadable($promise);
189+ $stream = React\Promise\ Stream\unwrapReadable($promise);
182190
183191$loop->addTimer(2.0, function () use ($stream) {
184192 $stream->close();
@@ -200,7 +208,7 @@ have written to the proxy will be forwarded transparently to the inner stream.
200208//$promise = someFunctionWhichResolvesWithAStream();
201209$promise = startUploadStream($uri);
202210
203- $stream = Stream\unwrapWritable($promise);
211+ $stream = React\Promise\ Stream\unwrapWritable($promise);
204212
205213$stream->write('hello');
206214$stream->end('world');
@@ -217,7 +225,7 @@ an `error` event and close:
217225``` php
218226$promise = startUploadStream($invalidUri);
219227
220- $stream = Stream\unwrapWritable($promise);
228+ $stream = React\Promise\ Stream\unwrapWritable($promise);
221229
222230$stream->on('error', function (Exception $error) {
223231 echo 'Error: ' . $error->getMessage();
@@ -236,7 +244,7 @@ You can `close()` the resulting stream at any time, which will either try to
236244``` php
237245$promise = startUploadStream($uri);
238246
239- $stream = Stream\unwrapWritable($promise);
247+ $stream = React\Promise\ Stream\unwrapWritable($promise);
240248
241249$loop->addTimer(2.0, function () use ($stream) {
242250 $stream->close();
0 commit comments