Skip to content

Commit a3205e1

Browse files
authored
feat: let timeout be configurable via $ opts (google#796)
1 parent b6420eb commit a3205e1

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/core.ts

+3
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ export interface Options {
5959
ac?: AbortController
6060
signal?: AbortSignal
6161
input?: string | Buffer | Readable | ProcessOutput | ProcessPromise
62+
timeout?: Duration
63+
timeoutSignal?: string
6264
stdio: StdioOptions
6365
verbose: boolean
6466
sync: boolean
@@ -246,6 +248,7 @@ export class ProcessPromise extends Promise<ProcessOutput> {
246248
const input = ($.input as ProcessPromise | ProcessOutput)?.stdout ?? $.input
247249

248250
if (input) this.stdio('pipe')
251+
if ($.timeout) this.timeout($.timeout, $.timeoutSignal)
249252

250253
$.log({
251254
kind: 'cmd',

test/core.test.js

+15
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,21 @@ describe('core', () => {
480480
assert.equal(signal, 'SIGKILL')
481481
})
482482

483+
test('timeout is configurable via opts', async () => {
484+
let exitCode, signal
485+
try {
486+
await $({
487+
timeout: 10,
488+
timeoutSignal: 'SIGKILL',
489+
})`sleep 999`
490+
} catch (p) {
491+
exitCode = p.exitCode
492+
signal = p.signal
493+
}
494+
assert.equal(exitCode, null)
495+
assert.equal(signal, 'SIGKILL')
496+
})
497+
483498
test('timeout() expiration works', async () => {
484499
let exitCode, signal
485500
try {

0 commit comments

Comments
 (0)