Skip to content

Instantly share code, notes, and snippets.

@sincerefly
Created January 15, 2019 08:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sincerefly/73c92a17552086a1016b24432891af4e to your computer and use it in GitHub Desktop.
Save sincerefly/73c92a17552086a1016b24432891af4e to your computer and use it in GitHub Desktop.
Async请求重试
// From: http://thecodebarbarian.com/common-async-await-design-patterns-in-node.js.html
const superagent = require('superagent');
const NUM_RETRIES = 3;
test();
async function test() {
let i;
for (i = 0; i < NUM_RETRIES; ++i) {
try {
await superagent.get('http://google.com/this-throws-an-error');
break;
} catch(err) {}
}
console.log(i); // 3
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment