diff --git a/src/Timer/Timers.php b/src/Timer/Timers.php index c183a637..bebe5520 100644 --- a/src/Timer/Timers.php +++ b/src/Timer/Timers.php @@ -30,7 +30,7 @@ public function getTime() public function add(TimerInterface $timer) { $interval = $timer->getInterval(); - $scheduledAt = $interval + $this->getTime(); + $scheduledAt = $interval + microtime(true); $this->timers->attach($timer, $scheduledAt); $this->scheduler->insert($timer, -$scheduledAt); diff --git a/tests/Timer/TimersTest.php b/tests/Timer/TimersTest.php new file mode 100644 index 00000000..0ca87e16 --- /dev/null +++ b/tests/Timer/TimersTest.php @@ -0,0 +1,29 @@ +getMockBuilder('React\EventLoop\LoopInterface') + ->getMock(); + + $timers = new Timers(); + $timers->tick(); + + // simulate a bunch of processing on stream events, + // part of which schedules a future timer... + sleep(1); + $timers->add(new Timer($loop, 0.5, function () { + $this->fail("Timer shouldn't be called"); + })); + + $timers->tick(); + } +}
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: