Promise Async Each
function each (condition, method, context, index) { | |
index = index === undefined ? 0 : index; | |
if (condition.call(context, index)) { | |
return Promise.resolve().then(function () { | |
return method.call(context, index); | |
}).then(each.bind(null, condition, method, context, index+1)); | |
} else { | |
return Promise.resolve(); | |
} | |
} | |
// console.log('before'); | |
// each(function (i) { return i < 10; }, function (i) { | |
// console.log(i++); | |
// // throw 'oops'; | |
// }).then(function () { | |
// console.log('actually after'); | |
// }).catch(function (error) { | |
// console.log(error); | |
// }); | |
// console.log('after but not'); | |
// Promise.resolve().then(function () { console.log('random'); }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment