Skip to content

Commit d717b2a

Browse files
authored
perf: remove redundant promise API overrides (#956)
1 parent c4f27cb commit d717b2a

File tree

2 files changed

+19
-38
lines changed

2 files changed

+19
-38
lines changed

src/core.ts

+19-26
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,25 @@ export const $: Shell & Options = new Proxy<Shell & Options>(
192192

193193
type Resolve = (out: ProcessOutput) => void
194194

195+
export interface ProcessPromise extends Promise<ProcessOutput> {
196+
then<R = ProcessOutput, E = ProcessOutput>(
197+
onfulfilled?:
198+
| ((value: ProcessOutput) => PromiseLike<R> | R)
199+
| undefined
200+
| null,
201+
onrejected?:
202+
| ((reason: ProcessOutput) => PromiseLike<E> | E)
203+
| undefined
204+
| null
205+
): Promise<R | E>
206+
catch<T = ProcessOutput>(
207+
onrejected?:
208+
| ((reason: ProcessOutput) => PromiseLike<T> | T)
209+
| undefined
210+
| null
211+
): Promise<ProcessOutput | T>
212+
}
213+
195214
export class ProcessPromise extends Promise<ProcessOutput> {
196215
private _command = ''
197216
private _from = ''
@@ -520,32 +539,6 @@ export class ProcessPromise extends Promise<ProcessOutput> {
520539
return this._nothrow ?? this._snapshot.nothrow
521540
}
522541

523-
// Promise API
524-
then<R = ProcessOutput, E = ProcessOutput>(
525-
onfulfilled?:
526-
| ((value: ProcessOutput) => PromiseLike<R> | R)
527-
| undefined
528-
| null,
529-
onrejected?:
530-
| ((reason: ProcessOutput) => PromiseLike<E> | E)
531-
| undefined
532-
| null
533-
): Promise<R | E> {
534-
if (this.isHalted() && !this.child) {
535-
throw new Error('The process is halted!')
536-
}
537-
return super.then(onfulfilled, onrejected)
538-
}
539-
540-
catch<T = ProcessOutput>(
541-
onrejected?:
542-
| ((reason: ProcessOutput) => PromiseLike<T> | T)
543-
| undefined
544-
| null
545-
): Promise<ProcessOutput | T> {
546-
return super.catch(onrejected)
547-
}
548-
549542
// Stream-like API
550543
private writable = true
551544
private emit(event: string, ...args: any[]) {

test/core.test.js

-12
Original file line numberDiff line numberDiff line change
@@ -633,18 +633,6 @@ describe('core', () => {
633633
assert.ok(fs.existsSync(filepath), 'The cmd should have been called')
634634
})
635635

636-
test('await on halted throws', async () => {
637-
const p = $({ halt: true })`sleep 1`
638-
let ok = true
639-
try {
640-
await p
641-
ok = false
642-
} catch (err) {
643-
assert.equal(err.message, 'The process is halted!')
644-
}
645-
assert.ok(ok, 'Expected failure!')
646-
})
647-
648636
test('sync process ignores halt option', () => {
649637
const p = $.sync({ halt: true })`echo foo`
650638
assert.equal(p.stdout, 'foo\n')

0 commit comments

Comments
 (0)