Created
September 23, 2010 03:40
-
-
Save kriskowal/593052 to your computer and use it in GitHub Desktop.
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
var Q = require("q"); | |
var HTTP = require("q-http"); | |
function httpReadRetry(url, timeout, times) { | |
return HTTP.read(url) | |
.then(function (content) { | |
return content; | |
}, function (error) { | |
if (times == 0) | |
throw new Error("Can't read " + JSON.stringify(url)); | |
return Q.delay(timeout) | |
.then(function () { | |
return httpReadRetry(url, timeout, times - 1); | |
}); | |
}); | |
} |
Really useful. Appreciate it.
My version with es6 syntax added and a slightly different form:
var Q = require('q');
var HTTP = require('q-http');
function httpReadRetry(url, timeout, times) {
return HTTP.read(url)
.then(content => content)
.catch((error) => {
if (times === 0)
throw new Error(`Cant read ${JSON.stringify(url)}`);
return Q.delay(timeout)
.then(() => httpReadRetry(url, timeout, times - 1));
});
}
How do I send a JSON POST request to q-io/http.request. It is expecting array of strings a body
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This was a huge help. Thank you.