Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
每当我运行协同生成器循环时,执行后什么都不会发生,进程就会挂起。完成后如何终止?
co(function *() { // code; })
Co()返回一个承诺。只需从循环中返回并使用.then(). 在这里,我们返回字符串"done",将其发送到console.log,然后终止进程。任何错误都将打印到控制台。
Co()
.then()
"done"
console.log
co(function *() { return "done"; }).then( res => { console.log(res); process.exit() } ).catch(err => console.error(err) );