Skip to content

Commit 437a80f

Browse files
authored
fix: timeout signal override (google#1075)
* fix: `timeout()` should not override predefined `_timeoutSignal` * test(bench): add buf-join aliternatives
1 parent a38d471 commit 437a80f

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/core.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,10 @@ export class ProcessPromise extends Promise<ProcessOutput> {
520520
return this
521521
}
522522

523-
timeout(d: Duration, signal = $.timeoutSignal): ProcessPromise {
523+
timeout(
524+
d: Duration,
525+
signal = this._timeoutSignal || $.timeoutSignal
526+
): ProcessPromise {
524527
if (this._resolved) return this
525528

526529
this._timeout = parseDuration(d)

test/bench/buf-join.mjs

+12
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,24 @@ cronometro({
2727
buf_arr_reduce_decode() {
2828
BUF_ARR.reduce((acc, buf) => acc + decoder.decode(buf), '')
2929
},
30+
buf_arr_reduce_to_string() {
31+
BUF_ARR.reduce((acc, buf) => acc + buf.toString('utf8'), '')
32+
},
3033
buf_arr_for_decode() {
3134
let res = ''
3235
for (const buf of BUF_ARR) {
3336
res += decoder.decode(buf)
3437
}
3538
},
39+
buf_arr_while_decode() {
40+
let res = ''
41+
let i = 0
42+
const bl = BUF_ARR.length
43+
while (i < bl) {
44+
res += decoder.decode(BUF_ARR[i])
45+
i++
46+
}
47+
},
3648
buf_arr_join() {
3749
BUF_ARR.join('')
3850
},

0 commit comments

Comments
 (0)