forked from nasa-gcn/architect-plugin-search
-
Notifications
You must be signed in to change notification settings - Fork 0
/
processes.ts
28 lines (24 loc) · 790 Bytes
/
processes.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/*!
* Copyright © 2023 United States Government as represented by the
* Administrator of the National Aeronautics and Space Administration.
* All Rights Reserved.
*
* SPDX-License-Identifier: Apache-2.0
*/
import { spawn as node_spawn } from 'node:child_process'
import type { ChildProcess } from 'node:child_process'
export async function spawn(...args: Parameters<typeof node_spawn>) {
const child = node_spawn(...args)
return new Promise<ReturnType<typeof node_spawn>>((resolve, reject) => {
child
.on('spawn', () => {
resolve(child)
})
.on('error', reject)
})
}
export async function untilTerminated(child: ChildProcess) {
return new Promise<number | null>((resolve, reject) => {
child.on('exit', resolve).on('error', reject)
})
}