Skip to content

Instantly share code, notes, and snippets.

@dt665m
Created January 30, 2018 05:45
Show Gist options
  • Save dt665m/e796293f62d391c39787f4421a29b9c3 to your computer and use it in GitHub Desktop.
Save dt665m/e796293f62d391c39787f4421a29b9c3 to your computer and use it in GitHub Desktop.
function retry(options, callback) {
var req = https.request(options, function(res) {
var acc = "";
res.on("data", function(msg) {
acc += msg.toString("utf-8");
});
res.on("end", function() {
//if ok, callback(null, 'some data'), otherwise RECURSE retry(options,callback)
});
});
req.end();
req.on('error', function(e) {
//check error and decide if we retry or callback(e)
});
}
//example usage:
tryUntilSuccess(options, function(err, resp) {
// do something with err or resp
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment