exception)) { return; } $this->exception = new CancelledException($previous); $callbacks = $this->callbacks; $this->callbacks = []; foreach ($callbacks as $callback) { Loop::queue($callback, $this->exception); } } public function subscribe(callable $callback): string { $id = $this->nextId++; if ($this->exception) { Loop::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 isset($this->exception); } public function throwIfRequested(): void { if (isset($this->exception)) { throw $this->exception; } } }