in packages/flow-dev-tools/src/utils/async.js [32:59]
function exec(cmd: string, options?: ExecOpts): Promise<string> {
return new Promise((resolve, reject) => {
const cp = cp_exec(cmd, options, (err, stdout, stderr) => {
if (err == null) {
resolve(stdout.toString());
} else {
reject([err, stdout, stderr]);
}
});
if (options != null && options.stdin != null) {
// If we just write a giant string it can lead to a crash
const chunks = splitIntoChunks(options.stdin, STDIN_WRITE_CHUNK_SIZE);
const write = (chunkIndex: number) => {
if (chunkIndex >= chunks.length) {
cp.stdin.end();
return;
}
const canContinue = cp.stdin.write(chunks[chunkIndex], 'utf8');
if (canContinue) {
write(chunkIndex + 1);
} else {
cp.stdin.once('drain', () => write(chunkIndex + 1));
}
};
write(0);
}
});
}