iterator = $iterator; $this->channel = $channel; $this->unlisten = $unlisten; $this->queue = new Internal\ReferenceQueue; } public function __destruct() { if ($this->unlisten) { $this->unlisten(); // Invokes $this->queue->complete(). } } /** * {@inheritdoc} */ public function onDestruct(callable $onComplete) { $this->queue->onDestruct($onComplete); } /** * {@inheritdoc} */ public function advance(): Promise { return $this->iterator->advance(); } /** * {@inheritdoc} * * @return \Amp\Postgres\Notification */ public function getCurrent(): Notification { return $this->iterator->getCurrent(); } /** * @return string Channel name. */ public function getChannel(): string { return $this->channel; } /** * Unlistens from the channel. No more values will be emitted from this listener. * * @return \Amp\Promise<\Amp\Postgres\CommandResult> * * @throws \Error If this method was previously invoked. */ public function unlisten(): Promise { if (!$this->unlisten) { throw new \Error("Already unlistened on this channel"); } /** @var \Amp\Promise $promise */ $promise = ($this->unlisten)($this->channel); $this->unlisten = null; $promise->onResolve([$this->queue, "unreference"]); return $promise; } }