Skip to content

Commit

Permalink
Merge pull request #196 from mbonneau/event-loop-update
Browse files Browse the repository at this point in the history
 Forward compatibility with react/event-loop 1.0 and 0.5 while still support 0.4
  • Loading branch information
davidwdan authored Apr 18, 2018
2 parents e44b2ae + c3d223a commit 0045d54
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"satooshi/php-coveralls": "~1.0",
"phpunit/phpcov": "^3.1",
"phpunit/phpunit": "^5.7",
"react/event-loop": "^0.4.2"
"react/event-loop": "^1.0 || ^0.5 || ^0.4.2"
},
"suggest": {
"react/event-loop": "Used for scheduling async operations"
Expand Down
4 changes: 2 additions & 2 deletions demo/subscribeOn/subscribeOn.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
// Change scheduler for here
$timer = $loop->addTimer(0.001, $handler);

return new CallbackDisposable(function () use ($timer) {
return new CallbackDisposable(function () use ($loop, $timer) {
// And change scheduler for here
if ($timer) {
$timer->cancel();
$loop->cancelTimer($timer);
}
});
});
Expand Down
4 changes: 2 additions & 2 deletions src/Scheduler/EventLoopScheduler.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public function __construct($timerCallableOrLoop)
$this->delayCallback = $timerCallableOrLoop instanceof LoopInterface ?
function ($ms, $callable) use ($timerCallableOrLoop) {
$timer = $timerCallableOrLoop->addTimer($ms / 1000, $callable);
return new CallbackDisposable(function () use ($timer) {
$timer->cancel();
return new CallbackDisposable(function () use ($timer, $timerCallableOrLoop) {
$timerCallableOrLoop->cancelTimer($timer);
});
} :
$timerCallableOrLoop;
Expand Down
12 changes: 6 additions & 6 deletions test/Rx/Scheduler/EventLoopSchedulerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ public function testScheduledItemsFromOutsideOfSchedulerDontCreateExtraTimers()
$timersExecuted++;
$action();
});
return new CallbackDisposable(function () use ($timer) {
$timer->cancel();
return new CallbackDisposable(function () use ($loop, $timer) {
$loop->cancelTimer($timer);
});
});

Expand Down Expand Up @@ -176,8 +176,8 @@ public function testMultipleSchedulesFromOutsideInSameTickDontCreateExtraTimers(
$timersExecuted++;
$action();
});
return new CallbackDisposable(function () use ($timer) {
$timer->cancel();
return new CallbackDisposable(function () use ($loop, $timer) {
$loop->cancelTimer($timer);
});
});

Expand Down Expand Up @@ -206,8 +206,8 @@ public function testThatStuffScheduledWayInTheFutureDoesntKeepTheLoopRunningIfDi
$timersExecuted++;
$action();
});
return new CallbackDisposable(function () use ($timer) {
$timer->cancel();
return new CallbackDisposable(function () use ($loop, $timer) {
$loop->cancelTimer($timer);
});
});

Expand Down

0 comments on commit 0045d54

Please sign in to comment.