UNPKG

ciorent

Version:

A lightweight, low-overhead concurrency library

44 lines (43 loc) 1.33 kB
/** * Continue the execution on next event loop cycle. * * You can `await` this **occasionally** in an expensive synchronous operation to avoid * * blocking the main thread and let other asynchronous task to run. */ export declare const nextTick: Promise<void>; /** * Sleep for a duration. * @param ms - Sleep duration in milliseconds */ export declare const sleep: (ms: number) => Promise<void>; /** * Sleep for a duration synchronously. * * This method blocks the current thread. * * On the browser it only works in workers. * @param ms - Sleep duration in milliseconds */ export declare const sleepSync: (ms: number) => void; /** * Spawn n sequential task * @param n * @param task - The function to run */ export declare const sequential: <const T extends any[]>(n: number, task: (...args: [...T, id: number]) => Promise<any>, ...args: T) => Promise<void>; /** * Spawn n concurrent tasks * @param n * @param task - The function to run */ export declare const spawn: < const T extends any[], const R >(n: number, task: (...args: [...T, id: number]) => Promise<R>, ...args: T) => Promise<R>[]; /** * Throttle function execution for a time period * @param ms - The time in milliseconds * @param limit - The call limit in the time period */ export declare const throttle: (ms: number, limit: number) => (() => Promise<void>);