Skip to content

Commit

Permalink
Update react/event-loop from ^0.4 to ^1.0 (#1)
Browse files Browse the repository at this point in the history
* Update react/event-loop from ^0.4 to ^1.0

- Replace $timer->cancel() with $loop->cancelTimer($timer)
- Replace $loop->nextTick() with $loop->futureTick()
- added workaround to run() - make sure callback is called with $loop argument

* Update react/event-loop from ^0.4 to ^1.0

- Update React\EventLoop\Timer\TimerInterface to React\EventLoop\TimerInterface
  • Loading branch information
timostamm authored and alexeyshockov committed Apr 30, 2019
1 parent 3c43063 commit c7d3ef6
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -15,7 +15,7 @@
}
],
"require": {
"react/event-loop": "^0.4",
"react/event-loop": "^1.0",
"guzzlehttp/promises": "^1.3",
"guzzlehttp/guzzle": "^6.2"
},
Expand Down
2 changes: 1 addition & 1 deletion example/simple_query.php
Expand Up @@ -9,7 +9,7 @@

require __DIR__ . '/../vendor/autoload.php';

run(function ($loop) use ($genFn) {
run(function ($loop) {
// Logger to show pretty messages with timestamps.
$logger = new Logger('default');
$logger->pushHandler(new StreamHandler('php://stdout', Logger::INFO));
Expand Down
4 changes: 2 additions & 2 deletions src/CurlMultiHandler.php
Expand Up @@ -5,7 +5,7 @@
use GuzzleHttp\Handler\CurlMultiHandler as BaseCurlMultiHandler;
use Psr\Http\Message\RequestInterface;
use React\EventLoop\LoopInterface;
use React\EventLoop\Timer\TimerInterface;
use React\EventLoop\TimerInterface;

class CurlMultiHandler extends BaseCurlMultiHandler
{
Expand Down Expand Up @@ -54,7 +54,7 @@ private function updateTimer($options = [])

// Deactive timer if there are no more active requests.
if (!$this->activeRequests && $this->timer) {
$this->timer->cancel();
$this->loop->cancelTimer($this->timer);
// Don't use unset(), it completely removes property from the object, so next access will be handled by
// parent's __get()!
$this->timer = null;
Expand Down
2 changes: 1 addition & 1 deletion src/ReactTaskQueue.php
Expand Up @@ -24,6 +24,6 @@ public function add(callable $task)
{
parent::add($task);

$this->loop->nextTick([$this, 'run']);
$this->loop->futureTick([$this, 'run']);
}
}
4 changes: 2 additions & 2 deletions src/Throttler.php
Expand Up @@ -6,7 +6,7 @@
use GuzzleHttp\Promise\PromiseInterface;
use Psr\Http\Message\RequestInterface;
use React\EventLoop\LoopInterface;
use React\EventLoop\Timer\TimerInterface;
use React\EventLoop\TimerInterface;

/**
* Abstract throttler for any async actions (that produce promises)
Expand Down Expand Up @@ -151,7 +151,7 @@ private function finishTimer()
{
// Nothing to do. Remove the timer, if there is one...
if (!$this->activeCalls && !count($this->queue) && $this->timer) {
$this->timer->cancel();
$this->loop->cancelTimer($this->timer);
// Don't use unset(), it completely removes property from the object!
$this->timer = null;
}
Expand Down
6 changes: 4 additions & 2 deletions src/functions.php
Expand Up @@ -23,7 +23,9 @@ function run(callable $action)

\GuzzleHttp\Promise\queue(new ReactTaskQueue($loop));

$loop->nextTick($action);
$loop->futureTick(function() use ($loop, $action){
$action($loop);
});

$loop->run();
}
Expand Down Expand Up @@ -51,7 +53,7 @@ function run_coroutine_fn(callable $coroutine)
/** @var \Exception $globalError */
$globalError = null;

$loop->nextTick(function () use ($coroutineFn, &$globalResult, &$globalError) {
$loop->futureTick(function () use ($coroutineFn, &$globalResult, &$globalError) {
$coroutineInvocation = coroutine($coroutineFn)
->then(function ($result) use (&$globalResult) {
return $globalResult = $result;
Expand Down

0 comments on commit c7d3ef6

Please sign in to comment.