Created
March 24, 2018 17:53
-
-
Save bryanjknight/9339852313d36a761d743c3b26c5ec8b to your computer and use it in GitHub Desktop.
bluebird-retry and request
This file contains hidden or 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
'use strict'; | |
const Promise = require('bluebird'); | |
const PromiseRetry = require('bluebird-retry'); | |
const request = require('request'); | |
const retryConfig = { | |
timeout: 20000, // 20 seconds | |
interval: 2000, // retry every 10 seconds | |
max_tries: 10 // 10 retries | |
} | |
new PromiseRetry(function() { | |
return new Promise(function(resolve, reject) { | |
request.get('http://localhost:18630', function(err, response, body) { | |
if(err) { | |
reject(err); | |
} | |
if(!err) { | |
resolve("success"); | |
} | |
}); | |
}); | |
}, retryConfig) | |
.then(function(result) { | |
console.log("Result: " + result); | |
} | |
).catch(function(err) { | |
console.error("Error: " + err); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment