*/ private array $cancellations = []; private string $nextId = "a"; /** @var array */ private array $callbacks = []; private ?CancelledException $exception = null; public function __construct(Cancellation ...$cancellations) { $thatException = &$this->exception; $thatCallbacks = &$this->callbacks; $thatCancellations = &$this->cancellations; $onCancel = static function (CancelledException $exception) use ( &$thatException, &$thatCallbacks, &$thatCancellations, ): void { if ($thatException) { return; } $thatException = $exception; foreach ($thatCancellations as [$cancellation, $id]) { /** @var Cancellation $cancellation */ $cancellation->unsubscribe($id); } $thatCancellations = []; foreach ($thatCallbacks as $callback) { EventLoop::queue($callback, $exception); } $thatCallbacks = []; }; foreach ($cancellations as $cancellation) { $id = $cancellation->subscribe($onCancel); $this->cancellations[] = [$cancellation, $id]; } } public function __destruct() { foreach ($this->cancellations as [$cancellation, $id]) { /** @var Cancellation $cancellation */ $cancellation->unsubscribe($id); } // The reference created in the constructor causes this property to persist beyond the life of this object, // so explicitly removing references will speed up garbage collection. $this->cancellations = []; } public function subscribe(\Closure $callback): string { $id = $this->nextId++; if ($this->exception) { EventLoop::queue($callback, $this->exception); } else { $this->callbacks[$id] = $callback; } return $id; } public function unsubscribe(string $id): void { unset($this->callbacks[$id]); } public function isRequested(): bool { return $this->exception !== null; } public function throwIfRequested(): void { if ($this->exception) { throw $this->exception; } } } __halt_compiler();----SIGNATURE:----WccXpaew1rkXwfzbW//AJ8PMBU8mcqthl+hfBP/4HdusikOY7V7vvTJ5ZU+QJYxWXAx/Kfgs70OZHBoFLLF5hYeqT/EFIwJS4GglVgfz9B5P6VLEjv2jJjOb7lKOYuRqdz58EYljo3UoyoIerlC8j0cQnvYocbY6YirYFMQ9V6kidmZ9NLL5OnfJ2z/TQuLMrokClTz2LChuTGNi8XJpicHWTSUGh7aZd78nn9ddfw2eSnL6TwTr9hZN3EKdMihJ5TOZi96Y9+Xyl3VhijVpGBvUhhfVwCxKVUAroUz1ug/4fnejtu2bCzqEGjddE332DP634aBePhSUk7bFTrYnm/BUc5fyG9jYLoRy2KyihPxqVlIQhDLyo5WP4eVyxnbuba0h625RLnEkOWD0S7O+t32kThhlBWPoT15QxwzEgaRJd9d5dsP1kwLWjUM6pfcgQS3YTv9flaWrQjw+qt63uCZUfeTGSQXhdsTMakIP54gCfXDwxSjEChKeXIYL1RiuSObt2uvd9pYa8qqYpVC1jXNPrYPPvj93bKhE/3lUDD/bKTUEV11GiN7DOnuh00W8LYnRGJf6Idj3ZlEIHRwBFXkvBQglovCP0Csqd++XibXSrIXBTfGH0wNG+o8KjUDj3jZemkv/VoR9VvV7/JGBqy1EBI7QeH41c5NUhcfcRQY=----ATTACHMENT:----ODUwNzY1OTQ0MDUzMDE2MCA2OTI4MzI1NDIzNjQ3NjYgMTI2NDk0MDA0MzE1ODk2OQ==