close
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Timer/Timers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
29 changes: 29 additions & 0 deletions tests/Timer/TimersTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace React\Tests\EventLoop\Timer;

use React\Tests\EventLoop\TestCase;
use React\EventLoop\Timer\Timer;
use React\EventLoop\Timer\Timers;

class TimersTest extends TestCase
{
public function testBlockedTimer()
{
$loop = $this
->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();
}
}