Commit 437a80f

Anton Golub <antongolub@antongolub.com>
2025-01-10 13:43:19
fix: timeout signal override (#1075)
* fix: `timeout()` should not override predefined `_timeoutSignal` * test(bench): add buf-join aliternatives
1 parent a38d471
Changed files (2)
src/core.ts
@@ -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)
test/bench/buf-join.mjs
@@ -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('')
   },