1
0
mirror of https://github.com/danog/amp.git synced 2024-12-03 09:57:51 +01:00

Fix ref/unref of Delayed after resolving

This commit is contained in:
Aaron Piotrowski 2020-04-20 12:01:50 -05:00
parent 23ac95fc6d
commit 4faeca163b
No known key found for this signature in database
GPG Key ID: ADD1EF783EDE9EEB

View File

@ -12,7 +12,7 @@ final class Delayed implements Promise
{
use Internal\Placeholder;
/** @var string Event loop watcher identifier. */
/** @var string|null Event loop watcher identifier. */
private $watcher;
/**
@ -22,6 +22,7 @@ final class Delayed implements Promise
public function __construct(int $time, $value = null)
{
$this->watcher = Loop::delay($time, function () use ($value) {
$this->watcher = null;
$this->resolve($value);
});
}
@ -33,7 +34,9 @@ final class Delayed implements Promise
*/
public function reference()
{
Loop::reference($this->watcher);
if ($this->watcher !== null) {
Loop::reference($this->watcher);
}
}
/**
@ -44,6 +47,8 @@ final class Delayed implements Promise
*/
public function unreference()
{
Loop::unreference($this->watcher);
if ($this->watcher !== null) {
Loop::unreference($this->watcher);
}
}
}