Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/test/base/stdout.ts
13389 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
/**
6
* Drains stdout and stderr, then exits the process
7
* @param exitCode The process exit code
8
*/
9
export async function drainStdoutAndExit(exitCode: number): Promise<never> {
10
await Promise.all([drainStream(process.stdout), drainStream(process.stderr)]);
11
process.exit(exitCode);
12
}
13
14
/**
15
* Drains a writable stream
16
* @param stream The stream to drain
17
*/
18
function drainStream(stream: NodeJS.WriteStream): Promise<void> {
19
const ok = stream.write('');
20
if (!ok) {
21
return new Promise(resolve => {
22
stream.once('drain', resolve);
23
});
24
}
25
return Promise.resolve();
26
}
27
28