UNPKG

asyncro

Version:

Asynchronous Array Utilities (for await)

3 lines (2 loc) 1.46 kB
!function(n,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r(n.asyncro={})}(this,function(n){function r(n,r){return Promise.all(n.map(r))}function t(n,r){return new Promise(function(t,e){return r().then(function(r){try{return n.push(r),t(n)}catch(n){return e(n)}}.bind(this),e)}.bind(this))}function e(n){var t=this;return function(e,i){return new Promise(function(t,u){var o;return r(e,i).then(function(r){try{return o=r,t(e[n](function(n,r){return o[r]}))}catch(n){return u(n)}}.bind(this),u)}.bind(t))}}function i(n,r,t){return new Promise(function(e,i){var u,o=0;return(u=function(n){for(;n;){if(n.then)return void n.then(u,i);try{if(n.pop){if(n.length)return n.pop()?s.call(this):n;n=c}else n=n.call(this)}catch(n){return i(n)}}}.bind(this))(f);function f(){return o<n.length?r(t,n[o],o,n).then(function(n){try{return t=n,c}catch(n){return i(n)}}.bind(this),i):[1]}function c(){return o++,f}function s(){return e(t)}}.bind(this))}var u=e("filter"),o=e("find"),f=e("every"),c=e("some");n.reduce=i,n.map=r,n.filter=u,n.find=o,n.every=f,n.some=c,n.parallel=function(n){return new Promise(function(r,t){return Promise.all(function(n){var r=Array.isArray(n)?[]:{};for(var t in n)n.hasOwnProperty(t)&&(r[t]=n[t]());return r}(n)).then(r,t)}.bind(this))},n.series=function(n){return new Promise(function(r,e){return r(i(n,t,[]))}.bind(this))}}); //# sourceMappingURL=asyncro.umd.js.map