I use node.js.
I use parallel method in async module to control asynchronous.
In each task function, run python code and get result.
But that result wrapped up in the Promise object.
code
const tasks = [
function(callback) {
pythonShell.run(options, (err, jsonArray)=> {
callback(null, jsonArray)
}
},
function(callback) {
pythonShell.run(options, (err, jsonArray)=> {
console.log(jsonArray) //1
callback(null, jsonArray)
}
}
]
async.parallel(tasks, (err, results) => {
if (err) return err.message
console.log(results)//2
});
first console.log
Promise {
[{...}, {...}]
}
second console.log
[
Promise {
[{...}, {...}]
},
Promise {
[{...}, {...}]
}
]
I only want json array in Promise { ... }
How can I get it?
console.log(results)withPromise.all(results).then(console.log)? - somethinghere.then(array => { /* Do something with the array of results */ })- somethinghere