0

Whenever I run a co generator loop, nothing happens after execution the process just hangs. How do I terminate after completion?

co(function *() {
    // code;
})
Evan Carroll
  • 78,363
  • 46
  • 261
  • 468

1 Answers1

0

Co() returns a promise. Simply return from the loop and handle it with .then(). Here we return the string "done", send that to console.log, and terminate the process. Any errors will be printed to the console.

co(function *() {
    return "done";
}).then(
  res => { console.log(res); process.exit() }
).catch(err => console.error(err) );
Evan Carroll
  • 78,363
  • 46
  • 261
  • 468