()
| 880 | } |
| 881 | |
| 882 | async close() { |
| 883 | // Prevent multiple invocations. |
| 884 | if (this.#serverClosing) { |
| 885 | return this.#serverClosing; |
| 886 | } |
| 887 | |
| 888 | // TODO would be awesome to set a delayed redirect when port changed to redirect to new _server_ |
| 889 | this.sendUpdateNotification({ |
| 890 | type: "eleventy.status", |
| 891 | status: "disconnected", |
| 892 | }); |
| 893 | |
| 894 | let promises = [] |
| 895 | if(this.updateServer) { |
| 896 | // Close all existing WS connections. |
| 897 | this.updateServer?.clients.forEach(socket => socket.close()); |
| 898 | promises.push(this._closeServer(this.updateServer)); |
| 899 | } |
| 900 | |
| 901 | if(this._server?.listening) { |
| 902 | promises.push(this._closeServer(this.server)); |
| 903 | } |
| 904 | |
| 905 | if(this.#watcher) { |
| 906 | promises.push(this.#watcher.close()); |
| 907 | this.#watcher = undefined; |
| 908 | } |
| 909 | |
| 910 | this.#serverClosing = Promise.all(promises).then(() => { |
| 911 | this.#serverState = "CLOSED"; |
| 912 | this.#serverClosing = undefined; |
| 913 | }); |
| 914 | |
| 915 | this.#serverState = "CLOSING"; |
| 916 | |
| 917 | return this.#serverClosing; |
| 918 | } |
| 919 | |
| 920 | sendError({ error }) { |
| 921 | this.sendUpdateNotification({ |
no test coverage detected