()
| 257 | } |
| 258 | |
| 259 | async _start() { |
| 260 | |
| 261 | if (this.phase === 'initialized' || |
| 262 | this.phase === 'started') { |
| 263 | |
| 264 | this._validateDeps(); |
| 265 | } |
| 266 | |
| 267 | if (this.phase === 'started') { |
| 268 | return; |
| 269 | } |
| 270 | |
| 271 | if (this.phase !== 'stopped' && |
| 272 | this.phase !== 'initialized') { |
| 273 | |
| 274 | throw new Error('Cannot start server while it is in ' + this.phase + ' phase'); |
| 275 | } |
| 276 | |
| 277 | if (this.phase !== 'initialized') { |
| 278 | await this._initialize(); |
| 279 | } |
| 280 | |
| 281 | this.phase = 'starting'; |
| 282 | this.started = true; |
| 283 | this.info.started = Date.now(); |
| 284 | |
| 285 | try { |
| 286 | await this._listen(); |
| 287 | } |
| 288 | catch (err) { |
| 289 | this.started = false; |
| 290 | this.phase = 'invalid'; |
| 291 | throw err; |
| 292 | } |
| 293 | |
| 294 | this.phase = 'started'; |
| 295 | this.events.emit('start'); |
| 296 | |
| 297 | try { |
| 298 | if (this.controlled) { |
| 299 | await Promise.all(this.controlled.map((control) => control.start())); |
| 300 | } |
| 301 | |
| 302 | await this._invoke('onPostStart'); |
| 303 | } |
| 304 | catch (err) { |
| 305 | this.phase = 'invalid'; |
| 306 | throw err; |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | _listen() { |
| 311 |
no test coverage detected