Skip to content

Instantly share code, notes, and snippets.

@liondancer
Created January 30, 2017 07:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liondancer/82f482f2931a08b2ee1fa83e17fd54e4 to your computer and use it in GitHub Desktop.
Save liondancer/82f482f2931a08b2ee1fa83e17fd54e4 to your computer and use it in GitHub Desktop.
const outerFunc = () => {
var i = 0
return new Promise(resolve => {
if (i < 3) {
i++
const innerFunc = () => {
return new Promise(resolve => {
return log.asyncCall().then(log => {
if (log) {
// some logic
} else {
resolve()
}
}).then(() => {
// continue iterating innerFunc()
return innerFunc();
});
})
};
// first iteration innerFunc()
return innerFunc().then(() => {
// once innerFunc() is complete, reiterate outerFunc()
return outerFunc();
});
} else {
resolve();
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment