diff options
Diffstat (limited to 'src/bun.js')
-rw-r--r-- | src/bun.js/http.exports.js | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/src/bun.js/http.exports.js b/src/bun.js/http.exports.js index 137906a5d..dda9664bb 100644 --- a/src/bun.js/http.exports.js +++ b/src/bun.js/http.exports.js @@ -925,7 +925,7 @@ export class ClientRequest extends OutgoingMessage { #fetchRequest; #signal = null; [kAbortController] = null; - + #timeoutTimer = null; #options; #finished; @@ -1183,7 +1183,7 @@ export class ClientRequest extends OutgoingMessage { this.#reusedSocket = false; this.#host = host; this.#protocol = protocol; - + this.#timeoutTimer = null; const headersArray = ArrayIsArray(headers); if (!headersArray) { var headers = options.headers; @@ -1258,9 +1258,25 @@ export class ClientRequest extends OutgoingMessage { setNoDelay(noDelay = true) { __DEBUG__ && debug(`${NODE_HTTP_WARNING}\n`, "WARN: ClientRequest.setNoDelay is a no-op"); } + [kClearTimeout]() { + if (this.#timeoutTimer) { + clearTimeout(this.#timeoutTimer); + this.#timeoutTimer = null; + } + } + + setTimeout(msecs, callback) { + if (this.#timeoutTimer) return this; + if (callback) { + this.on("timeout", callback); + } + + this.#timeoutTimer = setTimeout(async () => { + this.#timeoutTimer = null; + this[kAbortController]?.abort(); + this.emit("timeout"); + }, msecs); - setTimeout(timeout, callback) { - __DEBUG__ && debug(`${NODE_HTTP_WARNING}\n`, "WARN: ClientRequest.setTimeout is a no-op"); return this; } } |