1
0
mirror of https://github.com/danog/amp.git synced 2024-12-02 17:37:50 +01:00

Fix use before init

This commit is contained in:
Aaron Piotrowski 2020-10-22 23:03:58 -05:00
parent 80ecfe6b99
commit eec21c12c6
No known key found for this signature in database
GPG Key ID: ADD1EF783EDE9EEB

View File

@ -12,12 +12,12 @@ final class CombinedCancellationToken implements CancellationToken
/** @var callable[] */
private array $callbacks = [];
private ?CancelledException $exception;
private CancelledException $exception;
public function __construct(CancellationToken ...$tokens)
{
foreach ($tokens as $token) {
$id = $token->subscribe(function (CancelledException $exception) {
$id = $token->subscribe(function (CancelledException $exception): void {
$this->exception = $exception;
$callbacks = $this->callbacks;
@ -45,8 +45,8 @@ final class CombinedCancellationToken implements CancellationToken
{
$id = $this->nextId++;
if ($this->exception) {
Loop::defer(static fn (): Promise => call($callback)($this->exception));
if (isset($this->exception)) {
Loop::defer(static fn (): Promise => call($callback, $this->exception));
} else {
$this->callbacks[$id] = $callback;
}