UNPKG

ciorent

Version:

A lightweight, low-overhead concurrency library

42 lines (41 loc) 1.14 kB
/** * @module Other utilities */ /** * 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>; /** * Get the state of a promise on next tick: * - `0`: Input promise rejected * - `1`: Input promise resolves * - `2`: Input promise pending */ export declare const state: (p: Promise<any>) => Promise<0 | 1 | 2>; /** * Timeout a promise * @param p * @param ms */ export declare const timeout: <T>(p: Promise<T>, ms: number) => Promise<T | 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; export * as signal from "./signal.js"; export * as rateLimit from "./rate-limit.js"; export * as semaphore from "./semaphore.js";