* Close the client. Wait for pending commands.
()
| 1828 | * Close the client. Wait for pending commands. |
| 1829 | */ |
| 1830 | close() { |
| 1831 | return new Promise<void>(resolve => { |
| 1832 | clearTimeout(this._self.#pingTimer); |
| 1833 | this._self.#socket.close(); |
| 1834 | this._self.#clientSideCache?.onClose(); |
| 1835 | |
| 1836 | if (this._self.#queue.isEmpty()) { |
| 1837 | this._self.#unregisterFromMetrics(); |
| 1838 | this._self.#socket.destroySocket(); |
| 1839 | return resolve(); |
| 1840 | } |
| 1841 | |
| 1842 | const maybeClose = () => { |
| 1843 | if (!this._self.#queue.isEmpty()) return; |
| 1844 | |
| 1845 | this._self.#socket.off('data', maybeClose); |
| 1846 | this._self.#unregisterFromMetrics(); |
| 1847 | this._self.#socket.destroySocket(); |
| 1848 | resolve(); |
| 1849 | }; |
| 1850 | this._self.#socket.on('data', maybeClose); |
| 1851 | this._self.#credentialsSubscription?.dispose(); |
| 1852 | this._self.#credentialsSubscription = null; |
| 1853 | }); |
| 1854 | } |
| 1855 | |
| 1856 | /** |
| 1857 | * Destroy the client. Rejects all commands immediately. |