@@ -65,8 +65,7 @@ Once [installed](#install), you can use the following code to access an
65
65
HTTP webserver and send a large number of HTTP GET requests:
66
66
67
67
``` php
68
- $loop = React\EventLoop\Factory::create();
69
- $browser = new React\Http\Browser($loop);
68
+ $browser = new React\Http\Browser();
70
69
71
70
// load a huge array of URLs to fetch
72
71
$urls = file('urls.txt');
@@ -83,7 +82,6 @@ foreach ($urls as $url) {
83
82
});
84
83
}
85
84
86
- $loop->run();
87
85
```
88
86
89
87
See also the [ examples] ( examples ) .
@@ -162,8 +160,7 @@ The demonstration purposes, the examples in this documentation use
162
160
may use any Promise-based API with this project. Its API can be used like this:
163
161
164
162
``` php
165
- $loop = React\EventLoop\Factory::create();
166
- $browser = new React\Http\Browser($loop);
163
+ $browser = new React\Http\Browser();
167
164
168
165
$promise = $browser->get($url);
169
166
```
@@ -172,8 +169,7 @@ If you wrap this in a `Queue` instance as given above, this code will look
172
169
like this:
173
170
174
171
``` php
175
- $loop = React\EventLoop\Factory::create();
176
- $browser = new React\Http\Browser($loop);
172
+ $browser = new React\Http\Browser();
177
173
178
174
$q = new Queue(10, null, function ($url) use ($browser) {
179
175
return $browser->get($url);
@@ -226,7 +222,7 @@ underlying resources.
226
222
``` php
227
223
$promise = $q($url);
228
224
229
- $loop-> addTimer(2.0, function () use ($promise) {
225
+ Loop:: addTimer(2.0, function () use ($promise) {
230
226
$promise->cancel();
231
227
});
232
228
```
@@ -250,8 +246,8 @@ The resulting code with timeouts applied look something like this:
250
246
``` php
251
247
use React\Promise\Timer;
252
248
253
- $q = new Queue(10, null, function ($uri) use ($browser, $loop ) {
254
- return Timer\timeout($browser->get($uri), 2.0, $loop );
249
+ $q = new Queue(10, null, function ($uri) use ($browser) {
250
+ return Timer\timeout($browser->get($uri), 2.0);
255
251
});
256
252
257
253
$promise = $q($uri);
@@ -266,7 +262,7 @@ executing this operation can not take longer than the given timeout:
266
262
267
263
``` php
268
264
// usually not recommended
269
- $promise = Timer\timeout($q($url), 2.0, $loop );
265
+ $promise = Timer\timeout($q($url), 2.0);
270
266
```
271
267
272
268
Please refer to [ react/promise-timer] ( https://github.com/reactphp/promise-timer )
@@ -283,8 +279,7 @@ schedule all jobs while limiting concurrency to ensure no more than
283
279
resolves with the results of all jobs on success.
284
280
285
281
``` php
286
- $loop = React\EventLoop\Factory::create();
287
- $browser = new React\Http\Browser($loop);
282
+ $browser = new React\Http\Browser();
288
283
289
284
$promise = Queue::all(3, $urls, function ($url) use ($browser) {
290
285
return $browser->get($url);
@@ -360,8 +355,7 @@ resolves with the result of the first job on success and will then try
360
355
to ` cancel() ` all outstanding jobs.
361
356
362
357
``` php
363
- $loop = React\EventLoop\Factory::create();
364
- $browser = new React\Http\Browser($loop);
358
+ $browser = new React\Http\Browser();
365
359
366
360
$promise = Queue::any(3, $urls, function ($url) use ($browser) {
367
361
return $browser->get($url);
@@ -434,8 +428,7 @@ could look something like this:
434
428
``` php
435
429
use Clue\React\Block;
436
430
437
- $loop = React\EventLoop\Factory::create();
438
- $browser = new React\Http\Browser($loop);
431
+ $browser = new React\Http\Browser();
439
432
440
433
$promise = Queue::all(3, $urls, function ($url) use ($browser) {
441
434
return $browser->get($url);
@@ -462,8 +455,7 @@ all the async details from the outside:
462
455
*/
463
456
function download(array $uris)
464
457
{
465
- $loop = React\EventLoop\Factory::create();
466
- $browser = new React\Http\Browser($loop);
458
+ $browser = new React\Http\Browser();
467
459
468
460
$promise = Queue::all(3, $uris, function ($uri) use ($browser) {
469
461
return $browser->get($uri);
0 commit comments