Skip to content
Myr

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 file

Take it

The walk stopped after 200 commits: lines older than c8a6ed7 point at it.

Improve documentation (#1003)ehmickybefore adoptionc8a6ed7

lines 1–46why, one step back
1import {finished} from 'node:stream/promises';
2import {isStreamAbort} from '../resolve/wait-stream.js';34export const safeWaitForSubprocessStdin = async subprocessStdin => {5 if (subprocessStdin === undefined) {6 return;7 }89 try {10 await waitForSubprocessStdin(subprocessStdin);11 } catch {}12};1314export const safeWaitForSubprocessStdout = async subprocessStdout => {15 if (subprocessStdout === undefined) {16 return;17 }1819 try {20 await waitForSubprocessStdout(subprocessStdout);21 } catch {}22};2324export const waitForSubprocessStdin = async subprocessStdin => {25 await finished(subprocessStdin, {cleanup: true, readable: false, writable: true});26};2728export const waitForSubprocessStdout = async subprocessStdout => {29 await finished(subprocessStdout, {cleanup: true, readable: true, writable: false});30};3132// When `readable` or `writable` aborts/errors, awaits the subprocess, for the reason mentioned above33export const waitForSubprocess = async (subprocess, error) => {34 await subprocess;35 if (error) {36 throw error;37 }38};3940export const destroyOtherStream = (stream, isOpen, error) => {41 if (error && !isStreamAbort(error)) {42 stream.destroy(error);43 } else if (isOpen) {44 stream.destroy();45 }46};