UNPKG

batched-promise-all

Version:

:flight_departure: zero deps utility for keeping your memory footprint manageable with varying datasets

3 lines (2 loc) 2.04 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const t=function(){function t(){}return t.prototype.then=function(e,r){const o=new t,i=this.s;if(i){const t=1&i?e:r;if(t){try{n(o,1,t(this.v))}catch(t){n(o,2,t)}return o}return this}return this.o=function(t){try{const i=t.v;1&t.s?n(o,1,e?e(i):i):r?n(o,1,r(i)):n(o,2,i)}catch(t){n(o,2,t)}},o},t}();function n(e,r,o){if(!e.s){if(o instanceof t){if(!o.s)return void(o.o=n.bind(null,e,r));1&r&&(r=o.s),o=o.v}if(o&&o.then)return void o.then(n.bind(null,e,r),n.bind(null,e,2));e.s=r,e.v=o;const i=e.o;i&&i(e)}}function e(n){return n instanceof t&&1&n.s}const r="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator"))),exports.batchedPromiseAll=function(o,i,u){try{const c=function(t,n){const e=[];for(let r=0,o=t.length;r<o;r+=n)e.push(t.slice(r,r+n));return e}(o,u);let f=[],s=-1;const l=function(o,i,u){if("function"==typeof o[r]){var c,f,s,l=o[r]();if(function r(o){try{for(;!(c=l.next()).done;)if((o=i(c.value))&&o.then){if(!e(o))return void o.then(r,s||(s=n.bind(null,f=new t,2)));o=o.v}f?n(f,1,o):f=o}catch(e){n(f||(f=new t),2,e)}}(),l.return){var h=function(t){try{c.done||l.return()}catch(t){}return t};if(f&&f.then)return f.then(h,(function(t){throw h(t)}));h()}return f}if(!("length"in o))throw new TypeError("Object is not iterable");for(var a=[],y=0;y<o.length;y++)a.push(o[y]);return function(r,o,i){var u,c,f=-1;return function i(s){try{for(;++f<r.length;)if((s=o(f))&&s.then){if(!e(s))return void s.then(i,c||(c=n.bind(null,u=new t,2)));s=s.v}u?n(u,1,s):u=s}catch(e){n(u||(u=new t),2,e)}}(),u}(a,(function(t){return i(a[t])}))}(c,(function(t){return Promise.resolve(Promise.all(t.map(t=>(s++,i(t,s))))).then((function(t){f=f.concat(t)}))}));return Promise.resolve(l&&l.then?l.then((function(){return f})):f)}catch(t){return Promise.reject(t)}}; //# sourceMappingURL=batched-promise-all.cjs.production.min.js.map