Skip to content

Commit 4f94ac3

Browse files
authored
Apply suggestion from @rvagg
1 parent 3521f38 commit 4f94ac3

1 file changed

Lines changed: 4 additions & 14 deletions

File tree

‎branch-diff.js‎

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,12 @@ function replace (s, m) {
3434
return s
3535
}
3636

37-
async function spawnPromisified (...args) {
38-
const callback = args.pop()
39-
const cp = spawn(...args)
40-
41-
const closeEv = once(cp, 'close')
42-
closeEv.catch(() => {})
43-
44-
const result = await Promise.race([
45-
once(cp, 'error').then(e => Promise.reject(e[0])),
46-
callback(cp.stdout)
47-
])
48-
const [code, signal] = await closeEv
37+
async function spawnCollect (cmd, args, opts, consume) {
38+
const cp = spawn(cmd, args, opts)
39+
const [result, [code, signal]] = await Promise.all([consume(cp.stdout), once(cp, 'close')])
4940
if (code !== 0) {
50-
throw new Error(`Command "${args[0]} ${args[1].join(' ')}" exited with ${signal || code}`)
41+
throw new Error(`Command "${[cmd, ...args].join(' ')}" exited with ${signal || code}`)
5142
}
52-
5343
return result
5444
}
5545

0 commit comments

Comments
 (0)