mirror of
https://github.com/Strum355/mcshader-lsp.git
synced 2025-08-30 21:37:25 +00:00
Added an async process spawner using promises
This commit is contained in:
parent
558de42068
commit
ab0d4c977f
1 changed files with 26 additions and 0 deletions
26
src/asyncSpawn.ts
Normal file
26
src/asyncSpawn.ts
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
import { spawn } from 'child_process'
|
||||||
|
|
||||||
|
export function runLinter(...args: any[]) {
|
||||||
|
const child = spawn(args[0], ...(args.slice(1)))
|
||||||
|
let stderr = ''
|
||||||
|
|
||||||
|
child.stderr.on('data', data => {
|
||||||
|
stderr += data
|
||||||
|
})
|
||||||
|
|
||||||
|
const promise = new Promise<string>((resolve, reject) => {
|
||||||
|
child.on('error', () => reject(new Error('fatal error ${stderr}')))
|
||||||
|
|
||||||
|
child.on('exit', (code, signal) => {
|
||||||
|
switch (code) {
|
||||||
|
case 0:
|
||||||
|
case 2:
|
||||||
|
resolve(stderr)
|
||||||
|
default:
|
||||||
|
reject(new Error('standard error ${signal} ${stderr}'))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
return promise
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue