Skip to content

Commit

Permalink
feat: support signal opt
Browse files Browse the repository at this point in the history
closes google#768
relates google#734
  • Loading branch information
antongolub committed Apr 6, 2024
1 parent 7fa9bfc commit 5cad241
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 9 deletions.
18 changes: 12 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"typescript": "^5.4.4",
"which": "^4.0.0",
"yaml": "^2.4.1",
"zurk": "^0.0.32"
"zurk": "^0.1.0"
},
"publishConfig": {
"registry": "https://wombat-dressing-room.appspot.com"
Expand Down
2 changes: 2 additions & 0 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export interface Options {
[syncExec]: boolean
cwd?: string
ac?: AbortController
signal?: AbortSignal
input?: string | Buffer | Readable | ProcessOutput | ProcessPromise
verbose: boolean
sync: boolean
Expand Down Expand Up @@ -247,6 +248,7 @@ export class ProcessPromise extends Promise<ProcessOutput> {
cmd: $.prefix + this._command + $.postfix,
cwd: $.cwd ?? $[processCwd],
ac: $.ac,
signal: $.signal,
shell: typeof $.shell === 'string' ? $.shell : true,
env: $.env,
spawn: $.spawn,
Expand Down
14 changes: 14 additions & 0 deletions test/core.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,20 @@ describe('core', () => {
}
})

test('accepts AbortController `signal` separately', async () => {
const ac = new AbortController()
const signal = ac.signal
const p = $({ signal })`sleep 9999`
setTimeout(() => ac.abort(), 100)

try {
await p
assert.unreachable('should have thrown')
} catch ({ message }) {
assert.match(message, /The operation was aborted/)
}
})

test('kill() method works', async () => {
let p = $`sleep 9999`.nothrow()
setTimeout(() => {
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/js-project/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5cad241

Please sign in to comment.