UNPKG

@lzptec/concurrency

Version:

A Lightweight concurrency manager

2 lines 2.35 kB
'use strict';var i=Symbol("Interrupt"),o=Symbol("loop");function T(n){return {task:async function(t){await n(t);},results:[]}}function A(n){let t=new Array;return {task:async function(e){t.push(await n(e));},results:t}}function c(n){let t=new Array;return {task:async function(e){try{t.push({status:"fulfilled",value:await n(e)});}catch(r){t.push({status:"rejected",reason:r});}},results:t}}function p(n){let t=new Array;return {task:async function(e){await n(e)&&t.push(e);},results:t}}function l(n){let t=[false];return {task:async function(e){if(await n(e))return t[0]=true,i},results:t}}function f(n){let t=[];return {task:async function(e){if(await n(e))return t[0]=e,i},results:t}}function y(n){let t=[true];return {task:async function(e){if(!await n(e))return t[0]=false,i},results:t}}function b(n){let t=new Map;return {task:async function(e){let r=await n(e);t.has(r)?t.get(r).push(e):t.set(r,[e]);},results:[t]}}function d(n){return typeof n[Symbol.asyncIterator]=="function"}function m(n){return typeof n[Symbol.iterator]=="function"}function h(n){let t=d(n),e=m(n);if(!t&&!e)throw new TypeError("Expected `input("+typeof n+")` to be an `Iterable` or `AsyncIterable`");return t?n[Symbol.asyncIterator]():n[Symbol.iterator]()}function a(n){let t=typeof n;if(t!=="function")throw new TypeError("Expected `task("+t+")` to be a `function`")}function u(n){let t=typeof n;if(t!=="function")throw new TypeError("Expected `predicate("+t+")` to be a `function`")}var k=class{async forEach(t,e){return a(e),this[o](t,e)}async map(t,e){a(e);let{task:r,results:s}=A(e);return await this[o](t,r),s}async mapSettled(t,e){a(e);let{task:r,results:s}=c(e);return await this[o](t,r),s}async filter(t,e){u(e);let{task:r,results:s}=p(e);return await this[o](t,r),s}async some(t,e){u(e);let{task:r,results:s}=l(e);return await this[o](t,r),s[0]}async find(t,e){u(e);let{task:r,results:s}=f(e);return await this[o](t,r),s[0]}async every(t,e){u(e);let{task:r,results:s}=y(e);return await this[o](t,r),s[0]}async group(t,e){a(e);let{task:r,results:s}=b(e);return await this[o](t,r),Object.fromEntries(s[0])}};exports.a=i;exports.b=o;exports.c=T;exports.d=A;exports.e=c;exports.f=p;exports.g=l;exports.h=f;exports.i=y;exports.j=b;exports.k=h;exports.l=a;exports.m=u;exports.n=k;//# sourceMappingURL=chunk-CA3T2TT7.cjs.map //# sourceMappingURL=chunk-CA3T2TT7.cjs.map