mirror of
https://github.com/danog/amp.git
synced 2025-01-22 13:21:16 +01:00
Fix issues with interval = 0 repeat watchers, fixes #131
This commit is contained in:
parent
dbc853c3f1
commit
38ef4d9ffa
@ -61,6 +61,13 @@ class EvDriver extends Driver {
|
||||
$this->cancel($watcher->id);
|
||||
}
|
||||
|
||||
if ($watcher->type & Watcher::REPEAT && $watcher->value === 0) {
|
||||
// Disable and re-enable so it's not executed repeatedly in the same tick
|
||||
// See https://github.com/amphp/amp/issues/131
|
||||
$this->disable($watcher->id);
|
||||
$this->enable($watcher->id);
|
||||
}
|
||||
|
||||
try {
|
||||
$result = ($watcher->callback)($watcher->id, $watcher->data);
|
||||
|
||||
|
@ -90,6 +90,13 @@ class UvDriver extends Driver {
|
||||
$this->cancel($watcher->id); // Remove reference to watcher in parent.
|
||||
}
|
||||
|
||||
if ($watcher->type & Watcher::REPEAT && $watcher->value === 0) {
|
||||
// Disable and re-enable so it's not executed repeatedly in the same tick
|
||||
// See https://github.com/amphp/amp/issues/131
|
||||
$this->disable($watcher->id);
|
||||
$this->enable($watcher->id);
|
||||
}
|
||||
|
||||
try {
|
||||
$result = ($watcher->callback)($watcher->id, $watcher->data);
|
||||
|
||||
|
@ -1452,4 +1452,25 @@ abstract class DriverTest extends TestCase {
|
||||
|
||||
$this->loop->run();
|
||||
}
|
||||
|
||||
public function testTwoShortRepeatTimersWorkAsExpected() {
|
||||
$this->loop->repeat(0, function () use (&$j) {
|
||||
static $i = 0;
|
||||
if (++$i === 5) {
|
||||
$this->loop->stop();
|
||||
}
|
||||
$j = $i;
|
||||
});
|
||||
$this->loop->repeat(0, function () use (&$k) {
|
||||
static $i = 0;
|
||||
if (++$i === 5) {
|
||||
$this->loop->stop();
|
||||
}
|
||||
$k = $i;
|
||||
});
|
||||
|
||||
$this->loop->run();
|
||||
$this->assertLessThan(2, \abs($j - $k));
|
||||
$this->assertNotSame(0, $j);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user