Skip to content
Myr

Refactor `handlePromise()` (#289)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by ehmicky · committed by Sindre Sorhus · parent ed87275 · Browse files · 1 file+18 added−19 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+18 added−19 removed

  • other:+18 added−19 removed

1 file+18 added−19 removed

modified:index.js+18 added-19 removed
139 unmodified lines
140141 return getStream.buffer(stream, {maxBuffer});142}143144async function getPromiseResult({stdout, stderr, all}, {encoding, buffer, maxBuffer}, processDone) {145 const stdoutPromise = getStreamPromise(stdout, {encoding, buffer, maxBuffer});146 const stderrPromise = getStreamPromise(stderr, {encoding, buffer, maxBuffer});147 const allPromise = getStreamPromise(all, {encoding, buffer, maxBuffer: maxBuffer * 2});148149 try {150 return await Promise.all([processDone, stdoutPromise, stderrPromise, allPromise]);151 } catch (error) {152 return Promise.all([153 {error, code: error.code, signal: error.signal},154 getBufferedData(stdout, stdoutPromise),155 getBufferedData(stderr, stderrPromise),156 getBufferedData(all, allPromise)157 ]);158 }159}160161function makeError(result, options) {162 const {stdout, stderr, signal} = result;163 let {error} = result;164 const {code, command, timedOut, isCanceled, killed, parsed: {options: {timeout}}} = options;
138 unmodified lines
303}304305const execa = (file, args, options) => {306 const parsed = handleArgs(file, args, options);290 const {encoding, buffer, maxBuffer} = parsed.options;307 const command = joinCommand(file, args);308309 let spawned;310 try {
65 unmodified lines
376 }377 }), cleanup);378379 const handlePromise = async () => {364 const stdoutPromise = getStreamPromise(spawned.stdout, {encoding, buffer, maxBuffer});365 const stderrPromise = getStreamPromise(spawned.stderr, {encoding, buffer, maxBuffer});366 const allPromise = getStreamPromise(spawned.all, {encoding, buffer, maxBuffer: maxBuffer * 2});367368 let results;369 try {370 results = await Promise.all([processDone, stdoutPromise, stderrPromise, allPromise]);371 } catch (error) {372 const {code, signal} = error;373 results = await Promise.all([374 {error, code, signal},375 getBufferedData(spawned.stdout, stdoutPromise),376 getBufferedData(spawned.stderr, stderrPromise),377 getBufferedData(spawned.all, allPromise)378 ]);379 }380381 const [result, stdout, stderr, all] = results;380 const [result, stdout, stderr, all] = await getPromiseResult(spawned, parsed.options, processDone);381 result.stdout = handleOutput(parsed.options, stdout);382 result.stderr = handleOutput(parsed.options, stderr);383 result.all = handleOutput(parsed.options, all);384
133 unmodified lines