1 export const wait = (delay: number) => new Promise<void>((resolve) => setTimeout(resolve, delay));
4 * Runs each chunk from a chunks array and waits after each one has run (unless it's the last one).
6 export const runChunksDelayed = async <T>(
7 chunks: number[][] = [],
8 cb: (index: number) => Promise<T>,
13 for (let i = 0; i < chunks.length; ++i) {
14 promises.push(...chunks[i].map(cb));
15 if (i !== chunks.length - 1) {
20 return Promise.all(promises);
23 export const createPromise = <T>() => {
24 let resolve!: (value: T | PromiseLike<T>) => void;
25 let reject!: (reason?: any) => void;
27 const promise = new Promise<T>((innerResolve, innerReject) => {
28 resolve = innerResolve;
32 return { promise, resolve, reject };