This is my existing code. I tried to get data with a child process spawned, and the promise resolves after the child is terminated
const {spawn} = require('child_process')
const getDataFromChildProcess = params => new Promise(resolve => {
const child = spawn('script.js',[params])
let data = null
child.on('data',result => {
data = result
})
child.on('exit',() => {
resolve(data)
})
})
getDataFromChildProcess('foo')
.then(result => {
console.log(result)
})
How do I convert it into async-await style?