* Closes the transport. * * @private
(fn)
| 385 | * @private |
| 386 | */ |
| 387 | doClose(fn) { |
| 388 | debug("closing"); |
| 389 | |
| 390 | let closeTimeoutTimer; |
| 391 | |
| 392 | const onClose = () => { |
| 393 | clearTimeout(closeTimeoutTimer); |
| 394 | fn(); |
| 395 | this.onClose(); |
| 396 | }; |
| 397 | |
| 398 | if (this.writable) { |
| 399 | debug("transport writable - closing right away"); |
| 400 | this.send([{ type: "close" }]); |
| 401 | onClose(); |
| 402 | } else if (this.discarded) { |
| 403 | debug("transport discarded - closing right away"); |
| 404 | onClose(); |
| 405 | } else { |
| 406 | debug("transport not writable - buffering orderly close"); |
| 407 | this.shouldClose = onClose; |
| 408 | closeTimeoutTimer = setTimeout(onClose, this.closeTimeout); |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | /** |
| 413 | * Returns headers for a response. |