Created
July 22, 2015 22:49
-
-
Save jotak/1db63cb48f90e86dca74 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
var i = 0; | |
var async = function() { | |
return new Promise(function(resolve, reject) { | |
setTimeout(function() { | |
resolve(i++); | |
}, 500); | |
}); | |
}; | |
var start = function() { | |
return new Promise(function(resolve, reject) { | |
var result = []; | |
(function fetchData() { | |
async().then(function(response) { | |
result.push(response); | |
console.log(response); | |
if (response < 5) { | |
fetchData(); | |
} else { | |
resolve(result); | |
} | |
}); | |
})(); | |
}); | |
}; | |
start().then(function(result) { console.log(result); }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment