Created
January 30, 2018 05:45
-
-
Save dt665m/e796293f62d391c39787f4421a29b9c3 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
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