Skip to content
Myr

shared.js

This file

Path

lib/convert/shared.js

54 lines · 1.3 KiB · JavaScript

Last changed by

Add `binary` and `preserveNewlines` options to `subprocess.readable()` (#922)ehmickybefore adoption56ee48e

History of this file

Take it

Add `.readable()`, `.writable()` and `.duplex()` methods (#912)ehmickybefore adoption666f7f9

lines 1–46why, one step back
1import {finished} from 'node:stream/promises';
2import {isStreamAbort} from '../stream/wait.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};

Add `binary` and `preserveNewlines` options to `subprocess.readable()` (#922)ehmickybefore adoption56ee48e

lines 47–54why, one step back
47
48export const createDeferred = () => {49 let resolve;50 const promise = new Promise(resolve_ => {51 resolve = resolve_;52 });53 return Object.assign(promise, {resolve});54};