/** * Closes channel. * * Always returns a promise, because there can be outstanding messages to be processed. * * @param int $replyCode * @param string $replyText * @return PromiseInterface */ public function close($replyCode = 0, $replyText = "") { if ($this->state === ChannelStateEnum::CLOSED) { throw new ChannelException("Trying to close already closed channel #{$this->channelId}."); } if ($this->state === ChannelStateEnum::CLOSING) { return $this->closePromise; } $this->state = ChannelStateEnum::CLOSING; $this->client->channelClose($this->channelId, $replyCode, $replyText, 0, 0); $this->closeDeferred = new Deferred(); return $this->closePromise = $this->closeDeferred->promise()->then(function () { $this->client->removeChannel($this->channelId); }); }