diff --git a/README.md b/README.md index d23bcc2..3355aab 100644 --- a/README.md +++ b/README.md @@ -45,23 +45,22 @@ composer](http://getcomposer.org). addTimer(1, function () use ($callback) { + function ($callback, $errback) { + Loop::addTimer(1, function () use ($callback) { $callback('Slept for a whole second'); }); }, - function ($callback, $errback) use ($loop) { - $loop->addTimer(1, function () use ($callback) { + function ($callback, $errback) { + Loop::addTimer(1, function () use ($callback) { $callback('Slept for another whole second'); }); }, - function ($callback, $errback) use ($loop) { - $loop->addTimer(1, function () use ($callback) { + function ($callback, $errback) { + Loop::addTimer(1, function () use ($callback) { $callback('Slept for yet another whole second'); }); }, @@ -75,8 +74,6 @@ Async::parallel( throw $e; } ); - -$loop->run(); ``` ### Waterfall @@ -85,16 +82,15 @@ $loop->run(); addTimer(1, function () use ($prev, $callback) { + Loop::addTimer(1, function () use ($prev, $callback) { $callback($prev + 1); }); }; @@ -108,8 +104,6 @@ Async::waterfall(array( $callback(); }, )); - -$loop->run(); ``` ## Todo diff --git a/composer.json b/composer.json index 3e1ea58..fc685f7 100644 --- a/composer.json +++ b/composer.json @@ -30,10 +30,10 @@ }, "require-dev": { "phpunit/phpunit": "^5.7 || ^4.8.35", - "react/event-loop": "0.2.*" + "react/event-loop": "^1.2" }, "suggest": { - "react/event-loop": "You need some kind of event loop for this to make sense." + "react/event-loop": "You need an event loop for this to make sense." }, "autoload": { "psr-4": { "React\\Async\\": "src/" } diff --git a/tests/UtilParallelTest.php b/tests/UtilParallelTest.php index 9e73652..022f78c 100644 --- a/tests/UtilParallelTest.php +++ b/tests/UtilParallelTest.php @@ -3,6 +3,7 @@ namespace React\Tests\Async; use React\Async\Util; +use React\EventLoop\Loop; class UtilParallelTest extends TestCase { @@ -18,16 +19,14 @@ public function testParallelWithoutTasks() public function testParallelWithTasks() { - $loop = new \React\EventLoop\StreamSelectLoop(); - $tasks = array( - function ($callback, $errback) use ($loop) { - $loop->addTimer(0.1, function () use ($callback) { + function ($callback, $errback) { + Loop::addTimer(0.1, function () use ($callback) { $callback('foo'); }); }, - function ($callback, $errback) use ($loop) { - $loop->addTimer(0.1, function () use ($callback) { + function ($callback, $errback) { + Loop::addTimer(0.1, function () use ($callback) { $callback('bar'); }); }, @@ -41,7 +40,7 @@ function ($callback, $errback) use ($loop) { $timer = new Timer($this); $timer->start(); - $loop->run(); + Loop::run(); $timer->stop(); $timer->assertInRange(0.1, 0.2); @@ -78,15 +77,13 @@ public function testParallelWithDelayedError() { $called = 0; - $loop = new \React\EventLoop\StreamSelectLoop(); - $tasks = array( function ($callback, $errback) use (&$called) { $callback('foo'); $called++; }, - function ($callback, $errback) use ($loop) { - $loop->addTimer(0.001, function () use ($errback) { + function ($callback, $errback) { + Loop::addTimer(0.001, function () use ($errback) { $e = new \RuntimeException('whoops'); $errback($e); }); @@ -102,7 +99,7 @@ function ($callback, $errback) use (&$called) { Util::parallel($tasks, $callback, $errback); - $loop->run(); + Loop::run(); $this->assertSame(2, $called); } diff --git a/tests/UtilSeriesTest.php b/tests/UtilSeriesTest.php index 8713d64..ff4ce53 100644 --- a/tests/UtilSeriesTest.php +++ b/tests/UtilSeriesTest.php @@ -3,6 +3,7 @@ namespace React\Tests\Async; use React\Async\Util; +use React\EventLoop\Loop; class UtilSeriesTest extends TestCase { @@ -18,16 +19,14 @@ public function testSeriesWithoutTasks() public function testSeriesWithTasks() { - $loop = new \React\EventLoop\StreamSelectLoop(); - $tasks = array( - function ($callback, $errback) use ($loop) { - $loop->addTimer(0.05, function () use ($callback) { + function ($callback, $errback) { + Loop::addTimer(0.05, function () use ($callback) { $callback('foo'); }); }, - function ($callback, $errback) use ($loop) { - $loop->addTimer(0.05, function () use ($callback) { + function ($callback, $errback) { + Loop::addTimer(0.05, function () use ($callback) { $callback('bar'); }); }, @@ -41,7 +40,7 @@ function ($callback, $errback) use ($loop) { $timer = new Timer($this); $timer->start(); - $loop->run(); + Loop::run(); $timer->stop(); $timer->assertInRange(0.10, 0.20); diff --git a/tests/UtilWaterfallTest.php b/tests/UtilWaterfallTest.php index c50daa6..e3b6052 100644 --- a/tests/UtilWaterfallTest.php +++ b/tests/UtilWaterfallTest.php @@ -3,6 +3,7 @@ namespace React\Tests\Async; use React\Async\Util; +use React\EventLoop\Loop; class UtilWaterfallTest extends TestCase { @@ -18,21 +19,19 @@ public function testWaterfallWithoutTasks() public function testWaterfallWithTasks() { - $loop = new \React\EventLoop\StreamSelectLoop(); - $tasks = array( - function ($callback, $errback) use ($loop) { - $loop->addTimer(0.05, function () use ($callback) { + function ($callback, $errback) { + Loop::addTimer(0.05, function () use ($callback) { $callback('foo'); }); }, - function ($foo, $callback, $errback) use ($loop) { - $loop->addTimer(0.05, function () use ($callback, $foo) { + function ($foo, $callback, $errback) { + Loop::addTimer(0.05, function () use ($callback, $foo) { $callback($foo.'bar'); }); }, - function ($bar, $callback, $errback) use ($loop) { - $loop->addTimer(0.05, function () use ($callback, $bar) { + function ($bar, $callback, $errback) { + Loop::addTimer(0.05, function () use ($callback, $bar) { $callback($bar.'baz'); }); }, @@ -46,7 +45,7 @@ function ($bar, $callback, $errback) use ($loop) { $timer = new Timer($this); $timer->start(); - $loop->run(); + Loop::run(); $timer->stop(); $timer->assertInRange(0.15, 0.30);