UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 714 B
import{AsyncLocalStorage as e}from"node:async_hooks";import t from"p-map";async function runTasksWithConcurrency(n){let{tasks:r,limit:i,onTaskError:a,throwOnError:o=!1}=n,s=n.errorMode??`continue`;if(r.length===0)return{results:[],firstError:void 0,hasError:!1};let c=Number.isFinite(i)?Math.max(1,Math.min(Math.floor(i),r.length)):r.length,l=Array.from({length:r.length}),u,d=!1;return new Promise((n,i)=>{let runOne=async(e,t)=>{if(!(s===`stop`&&d))try{l[t]=await e()}catch(e){d||=(u=e,!0);let n=e;try{a?.(e,t)}catch(e){n=e}o&&i(n)}},f=e.bind((e,t)=>Promise.resolve().then(()=>runOne(e,t)));t(r.slice(),f,{concurrency:c}).then(()=>n({results:l,firstError:u,hasError:d}),i)})}export{runTasksWithConcurrency as t};