Files
vscode/extensions/copilot/test/base/stdout.ts
kieferrm 333d9a4053 Hello Copilot
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
2025-06-27 11:35:20 +02:00

27 lines
925 B
TypeScript

/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
/**
* Drains stdout and stderr, then exits the process
* @param exitCode The process exit code
*/
export async function drainStdoutAndExit(exitCode: number): Promise<never> {
await Promise.all([drainStream(process.stdout), drainStream(process.stderr)]);
process.exit(exitCode);
}
/**
* Drains a writable stream
* @param stream The stream to drain
*/
function drainStream(stream: NodeJS.WriteStream): Promise<void> {
const ok = stream.write('');
if (!ok) {
return new Promise(resolve => {
stream.once('drain', resolve);
});
}
return Promise.resolve();
}