( httpServer: HttpServer, port: number, host: string | undefined, )
| 188 | } |
| 189 | |
| 190 | async function tryBindServer( |
| 191 | httpServer: HttpServer, |
| 192 | port: number, |
| 193 | host: string | undefined, |
| 194 | ): Promise< |
| 195 | { success: true } | { success: false; error: NodeJS.ErrnoException } |
| 196 | > { |
| 197 | return new Promise((resolve) => { |
| 198 | const onError = (e: NodeJS.ErrnoException) => { |
| 199 | httpServer.off('error', onError) |
| 200 | httpServer.off('listening', onListening) |
| 201 | resolve({ success: false, error: e }) |
| 202 | } |
| 203 | const onListening = () => { |
| 204 | httpServer.off('error', onError) |
| 205 | httpServer.off('listening', onListening) |
| 206 | resolve({ success: true }) |
| 207 | } |
| 208 | |
| 209 | httpServer.on('error', onError) |
| 210 | httpServer.on('listening', onListening) |
| 211 | |
| 212 | httpServer.listen(port, host) |
| 213 | }) |
| 214 | } |
| 215 | |
| 216 | const MAX_PORT = 65535 |
| 217 |
no test coverage detected