8000 feat: let timeout be configurable via $ opts by antongolub · Pull Request #796 · google/zx · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: let timeout be configurable via $ opts #796

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ export interface Options {
ac?: AbortController
signal?: AbortSignal
input?: string | Buffer | Readable | ProcessOutput | ProcessPromise
timeout?: Duration
timeoutSignal?: string
stdio: StdioOptions
verbose: boolean
sync: boolean
Expand Down Expand Up @@ -246,6 +248,7 @@ export class ProcessPromise extends Promise<ProcessOutput> {
const input = ($.input as ProcessPromise | ProcessOutput)?.stdout ?? $.input

if (input) this.stdio('pipe')
if ($.timeout) this.timeout($.timeout, $.timeoutSignal)

$.log({
kind: 'cmd',
Expand Down
15 changes: 15 additions & 0 deletions test/core.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,21 @@ describe('core', () => {
assert.equal(signal, 'SIGKILL')
})

test('timeout is configurable via opts', async () => {
let exitCode, signal
try {
await $({
timeout: 10,
timeoutSignal: 'SIGKILL',
})`sleep 999`
} catch (p) {
exitCode = p.exitCode
signal = p.signal
}
assert.equal(exitCode, null)
assert.equal(signal, 'SIGKILL')
})

test('timeout() expiration works', async () => {
let exitCode, signal
try {
Expand Down
0