* Closes the transport. * * @private
(fn: () => void)
| 344 | * @private |
| 345 | */ |
| 346 | override doClose(fn: () => void) { |
| 347 | debug("closing"); |
| 348 | |
| 349 | let closeTimeoutTimer; |
| 350 | |
| 351 | if (this.dataReq) { |
| 352 | debug("aborting ongoing data request"); |
| 353 | this.dataReq.destroy(); |
| 354 | } |
| 355 | |
| 356 | const onClose = () => { |
| 357 | clearTimeout(closeTimeoutTimer); |
| 358 | fn(); |
| 359 | this.onClose(); |
| 360 | }; |
| 361 | |
| 362 | if (this.writable) { |
| 363 | debug("transport writable - closing right away"); |
| 364 | this.send([{ type: "close" }]); |
| 365 | onClose(); |
| 366 | } else if (this.discarded) { |
| 367 | debug("transport discarded - closing right away"); |
| 368 | onClose(); |
| 369 | } else { |
| 370 | debug("transport not writable - buffering orderly close"); |
| 371 | this.shouldClose = onClose; |
| 372 | closeTimeoutTimer = setTimeout(onClose, this.closeTimeout); |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | /** |
| 377 | * Returns headers for a response. |