Skip to content

Instantly share code, notes, and snippets.

@Sharp6
Created March 2, 2017 19:58
Show Gist options
  • Save Sharp6/9cb6b15e9e6df870d82baf81300fe130 to your computer and use it in GitHub Desktop.
Save Sharp6/9cb6b15e9e6df870d82baf81300fe130 to your computer and use it in GitHub Desktop.
Recursive async
var request = require('request');
var doCallWithRecover = function() {
return new Promise(function(resolve, reject) {
request('https://pdbss.herokuapp.com', function(err,data) {
if(checkIfOk(data)) {
resolve(data);
} else {
return doCallWithRecover();
}
})
});
};
var checkIfOk = function(something) {
return false;
}
doCallWithRecover()
.then(data => console.log(JSON.parse(data.body)))
.catch(err => { console.log(err) });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment