Created
January 15, 2019 08:52
-
-
Save sincerefly/73c92a17552086a1016b24432891af4e to your computer and use it in GitHub Desktop.
Async请求重试
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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