*/ 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:----tVUwXM064l8eRc6XETAfarWygueihfW4bENI+jCjrjf2g+eithdOKvsu2illjIIUqSz23DLoQEqfeEq+yDkr7UllTmJS9IBIrjmwajnuOTSUgrmBmWQKCr4Fbfn+GWpPza2Ib4MUqS33PW8b+VffPLPOyEuM0h0jyKNNtjF1MQ2fD/xahJeuvdIMx8PuE7sPOGy2vSbfVD17RlktbKRNW4hym6pDyYlkN+Rqx29NvPhYXopU6GWlUHZDhnutirMGmY1Kb1BzIsot9rL+crlXvtiCwW7rftBrInDRlQ+yoQ+56t2uXO9Y8lhwnCuGE7IHNoEWOvGv704zI4wVR/nu2rv+wkQUyvEdC+cmQMcOso5zeeyD3tpIGXo3Tus9V6ni7IIt9Rccldv5eENtqbil980LIckBYBVfACAcPb3yiNmakSSB4hzBeEVfxXNO9+60feH6icXQfsowhMcJHDgezRELhXuHO1yDqZQhBamyJ890SySmW5KRUchPnr3nX+xOt6/DmNrLksr7SqltMf/9560Xd84zyPjj3VFAhn0yTWb1aDofghu2G0Hv0CAbsY/61OdPeAV9q0u8VjxTw6hMmWWQSwMkjpiX8ZK9VjjMYcH1tqVxhsMJlab4rX5fAGx/yeeo5waRcaJ2h/ucfJcdHWo5QRIr5mI2OSjeatFHkCU=----ATTACHMENT:----NDY5ODc4ODgwODAyMzIxNyA5NTMyNjgyMjg2NjIwOTUxIDg3MTQ0MDk5NzA3NjY1NjA=