Skip to content

Instantly share code, notes, and snippets.

@jotak
Created July 22, 2015 22:49
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 jotak/1db63cb48f90e86dca74 to your computer and use it in GitHub Desktop.
Save jotak/1db63cb48f90e86dca74 to your computer and use it in GitHub Desktop.
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