shared.js
This file
Path
lib/convert/shared.js
46 lines · 1.2 KiB · JavaScript
Last changed by
Refactor `subprocess.kill(error)` (#1023)ehmickybefore adoption9de7335
History of this fileTake it
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647import {finished} from 'node:stream/promises';import {isStreamAbort} from '../resolve/wait-stream.js';
export const safeWaitForSubprocessStdin = async subprocessStdin => { if (subprocessStdin === undefined) { return; }
try { await waitForSubprocessStdin(subprocessStdin); } catch {}};
export const safeWaitForSubprocessStdout = async subprocessStdout => { if (subprocessStdout === undefined) { return; }
try { await waitForSubprocessStdout(subprocessStdout); } catch {}};
export const waitForSubprocessStdin = async subprocessStdin => { await finished(subprocessStdin, {cleanup: true, readable: false, writable: true});};
export const waitForSubprocessStdout = async subprocessStdout => { await finished(subprocessStdout, {cleanup: true, readable: true, writable: false});};
// When `readable` or `writable` aborts/errors, awaits the subprocess, for the reason mentioned aboveexport const waitForSubprocess = async (subprocess, error) => { await subprocess; if (error) { throw error; }};
export const destroyOtherStream = (stream, isOpen, error) => { if (error && !isStreamAbort(error)) { stream.destroy(error); } else if (isOpen) { stream.destroy(); }};