Skip to content

Commit e515aaa

Browse files
authored
Merge pull request #51 from andrewminerd/timer_fix
StreamSelectLoop: Use fresh time so Timers added during stream events are accurate
2 parents 626faeb + ebed326 commit e515aaa

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/Timer/Timers.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function getTime()
3030
public function add(TimerInterface $timer)
3131
{
3232
$interval = $timer->getInterval();
33-
$scheduledAt = $interval + $this->getTime();
33+
$scheduledAt = $interval + microtime(true);
3434

3535
$this->timers->attach($timer, $scheduledAt);
3636
$this->scheduler->insert($timer, -$scheduledAt);

tests/Timer/TimersTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace React\Tests\EventLoop\Timer;
4+
5+
use React\Tests\EventLoop\TestCase;
6+
use React\EventLoop\Timer\Timer;
7+
use React\EventLoop\Timer\Timers;
8+
9+
class TimersTest extends TestCase
10+
{
11+
public function testBlockedTimer()
12+
{
13+
$loop = $this
14+
->getMockBuilder('React\EventLoop\LoopInterface')
15+
->getMock();
16+
17+
$timers = new Timers();
18+
$timers->tick();
19+
20+
// simulate a bunch of processing on stream events,
21+
// part of which schedules a future timer...
22+
sleep(1);
23+
$timers->add(new Timer($loop, 0.5, function () {
24+
$this->fail("Timer shouldn't be called");
25+
}));
26+
27+
$timers->tick();
28+
}
29+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

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:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy