const f = n => new Promise((resolve, reject) => {
setTimeout(()=>{
if (n > 2){
resolve({result: `${n} is higher than 2`});
} else {
resolve({error: `${n} is lower than 2`});
}
}, 1000);
});
function *m(){
const {result, error} = yield f(parseInt(process.argv[2]));
if(error){
console.log(error);
} else {
console.log(result);
}
}
m();
I'm using node.js v6.2 and when I execute node file.js 344
there is no result.
If I put a debugger inside whatever function I choose, it doesn't stop while in debug mode.
It only stops if I extract the iterator with const it = m();
But I've seen examples where the above pattern seems to be correct. What am I missing?
Thank you.