| 697 | #callFlushCallbackOnDrain(cb) { |
| 698 | this.#flushPending = true; |
| 699 | const onDrain = () => { |
| 700 | // Only if _fsync is false to avoid double fsync |
| 701 | if (!this.#fsync && !this.#destroyed) { |
| 702 | try { |
| 703 | this.#fs.fsync(this.#fd, (err) => { |
| 704 | this.#flushPending = false; |
| 705 | // If the fd is closed, we ignore the error. |
| 706 | if (err?.code === 'EBADF') { |
| 707 | cb(); |
| 708 | return; |
| 709 | } |
| 710 | cb(err); |
| 711 | }); |
| 712 | } catch (err) { |
| 713 | this.#flushPending = false; |
| 714 | cb(err); |
| 715 | } |
| 716 | } else { |
| 717 | this.#flushPending = false; |
| 718 | cb(); |
| 719 | } |
| 720 | this.off('error', onError); |
| 721 | }; |
| 722 | const onError = (err) => { |
| 723 | this.#flushPending = false; |
| 724 | cb(err); |