Created
December 4, 2016 02:29
-
-
Save bayleedev/6da0ebeaf408853b428d851b1decd035 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 testApiRecursive (data) { | |
console.log('calling it', data) | |
return Promise.resolve().then(() => { | |
if (Math.round(Math.random() * 10000) % 20 === 0) { | |
// true 1/20th of the time | |
return data | |
} else { | |
return new Promise((resolve) => { | |
setTimeout(resolve, 250) // wait 250ms to run again | |
}).then(testApiRecursive.bind(this, data)) | |
} | |
}) | |
} | |
testApiRecursive(255).then((data) => { | |
console.log('tadah', data) | |
}).catch((error) => { | |
console.log('error', error) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment