UNPKG

promise-throttle-all

Version:
8 lines (7 loc) 989 B
/*! * promise-throttle-all v1.1.1 * (c) Robin Pokorny * Released under the MIT License. */ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).promiseThrottleAll={})}(this,(function(e){"use strict";const t=Symbol("not-settled");e.throttleAll=(e,o)=>{if(!Number.isInteger(e)||e<1)throw new TypeError(`Expected \`limit\` to be a finite number > 0, got \`${e}\` (${typeof e})`);if(!Array.isArray(o)||!o.every((e=>"function"==typeof e)))throw new TypeError("Expected `tasks` to be a list of functions returning a promise");return new Promise(((n,r)=>{const i=Array(o.length).fill(t),f=o.entries(),s=()=>{const{done:e,value:o}=f.next();if(e){return void(!i.includes(t)&&n(i))}const[l,u]=o;u().then((e=>{i[l]=e,s()}),r)};Array(e).fill(0).forEach(s)}))},Object.defineProperty(e,"__esModule",{value:!0})})); //# sourceMappingURL=index.umd.min.js.map