Closed
Description
If you run the following code
$loop = \React\EventLoop\Factory::create();
for ($counter = 1; $counter <= 5; $counter++) {
echo "Counter before loop {$counter}\n";
$loop->addTimer(0.001, function () use ($counter) {
echo "Counter in loop {$counter}\n";
});
}
$loop->run();
You get this output
Counter before loop 1
Counter before loop 2
Counter before loop 3
Counter before loop 4
Counter before loop 5
Counter in loop 1
Counter in loop 5
Counter in loop 4
Counter in loop 3
Counter in loop 2
The counter within the loop should be in the same order as the counter before the loop.
It looks like the issue is with line 33 in Timers.php. It adds the interval to $this->getTime()
, which doesn't change.
A simple fix is to replace getTime() with updateTime(), which works as expected, but I'm not sure it that causes issues anywhere else.
$scheduledAt = $interval + $this->updateTime();
Let me know if you don't think it'll cause any other issues and I'll submit a PR.
Metadata
Metadata
Assignees
Labels
No labels