Skip to content

Commit

Permalink
fix: timeout signal override (#1075)
Browse files Browse the repository at this point in the history
* fix: `timeout()` should not override predefined `_timeoutSignal`

* test(bench): add buf-join aliternatives
  • Loading branch information
antongolub authored Jan 10, 2025
1 parent a38d471 commit 437a80f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,10 @@ export class ProcessPromise extends Promise<ProcessOutput> {
return this
}

timeout(d: Duration, signal = $.timeoutSignal): ProcessPromise {
timeout(
d: Duration,
signal = this._timeoutSignal || $.timeoutSignal
): ProcessPromise {
if (this._resolved) return this

this._timeout = parseDuration(d)
Expand Down
12 changes: 12 additions & 0 deletions test/bench/buf-join.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,24 @@ cronometro({
buf_arr_reduce_decode() {
BUF_ARR.reduce((acc, buf) => acc + decoder.decode(buf), '')
},
buf_arr_reduce_to_string() {
BUF_ARR.reduce((acc, buf) => acc + buf.toString('utf8'), '')
},
buf_arr_for_decode() {
let res = ''
for (const buf of BUF_ARR) {
res += decoder.decode(buf)
}
},
buf_arr_while_decode() {
let res = ''
let i = 0
const bl = BUF_ARR.length
while (i < bl) {
res += decoder.decode(BUF_ARR[i])
i++
}
},
buf_arr_join() {
BUF_ARR.join('')
},
Expand Down

0 comments on commit 437a80f

Please sign in to comment.