简体   繁体   中英

How to loop async code with a try-catch block inside using generators?

This simple code would enter the catch just once. How can I loop this with the try catch?

run(function* (gen) {
  while (true) {
    try {
      yield request('http://www.unexistanturl.com', gen());
    } catch (err) {
      debug(err);
    }
  }
})
run(function* (gen) {
  while (true) {
      yield function(){
        try {
          request('http://www.unexistanturl.com', gen());
        } catch (err) {
          debug(err);
        }
      }();
  }
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM