@@ -65,8 +65,7 @@ Once [installed](#install), you can use the following code to access an
6565HTTP webserver and send a large number of HTTP GET requests:
6666
6767``` php
68- $loop = React\EventLoop\Factory::create();
69- $browser = new React\Http\Browser($loop);
68+ $browser = new React\Http\Browser();
7069
7170// load a huge array of URLs to fetch
7271$urls = file('urls.txt');
@@ -83,7 +82,6 @@ foreach ($urls as $url) {
8382 });
8483}
8584
86- $loop->run();
8785```
8886
8987See also the [ examples] ( examples ) .
@@ -162,8 +160,7 @@ The demonstration purposes, the examples in this documentation use
162160may use any Promise-based API with this project. Its API can be used like this:
163161
164162``` php
165- $loop = React\EventLoop\Factory::create();
166- $browser = new React\Http\Browser($loop);
163+ $browser = new React\Http\Browser();
167164
168165$promise = $browser->get($url);
169166```
@@ -172,8 +169,7 @@ If you wrap this in a `Queue` instance as given above, this code will look
172169like this:
173170
174171``` php
175- $loop = React\EventLoop\Factory::create();
176- $browser = new React\Http\Browser($loop);
172+ $browser = new React\Http\Browser();
177173
178174$q = new Queue(10, null, function ($url) use ($browser) {
179175 return $browser->get($url);
@@ -226,7 +222,7 @@ underlying resources.
226222``` php
227223$promise = $q($url);
228224
229- $loop-> addTimer(2.0, function () use ($promise) {
225+ Loop:: addTimer(2.0, function () use ($promise) {
230226 $promise->cancel();
231227});
232228```
@@ -250,8 +246,8 @@ The resulting code with timeouts applied look something like this:
250246``` php
251247use React\Promise\Timer;
252248
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);
255251});
256252
257253$promise = $q($uri);
@@ -266,7 +262,7 @@ executing this operation can not take longer than the given timeout:
266262
267263``` php
268264// usually not recommended
269- $promise = Timer\timeout($q($url), 2.0, $loop );
265+ $promise = Timer\timeout($q($url), 2.0);
270266```
271267
272268Please 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
283279resolves with the results of all jobs on success.
284280
285281``` php
286- $loop = React\EventLoop\Factory::create();
287- $browser = new React\Http\Browser($loop);
282+ $browser = new React\Http\Browser();
288283
289284$promise = Queue::all(3, $urls, function ($url) use ($browser) {
290285 return $browser->get($url);
@@ -360,8 +355,7 @@ resolves with the result of the first job on success and will then try
360355to ` cancel() ` all outstanding jobs.
361356
362357``` php
363- $loop = React\EventLoop\Factory::create();
364- $browser = new React\Http\Browser($loop);
358+ $browser = new React\Http\Browser();
365359
366360$promise = Queue::any(3, $urls, function ($url) use ($browser) {
367361 return $browser->get($url);
@@ -434,8 +428,7 @@ could look something like this:
434428``` php
435429use Clue\React\Block;
436430
437- $loop = React\EventLoop\Factory::create();
438- $browser = new React\Http\Browser($loop);
431+ $browser = new React\Http\Browser();
439432
440433$promise = Queue::all(3, $urls, function ($url) use ($browser) {
441434 return $browser->get($url);
@@ -462,8 +455,7 @@ all the async details from the outside:
462455 */
463456function download(array $uris)
464457{
465- $loop = React\EventLoop\Factory::create();
466- $browser = new React\Http\Browser($loop);
458+ $browser = new React\Http\Browser();
467459
468460 $promise = Queue::all(3, $uris, function ($uri) use ($browser) {
469461 return $browser->get($uri);
0 commit comments