MCPcopy Create free account
hub / github.com/ether/etherpad / timesLimit

Function timesLimit

src/node/utils/promises.ts:47–58  ·  view source on GitHub ↗
(total: number, concurrency: number, promiseCreator: Function)

Source from the content-addressed store, hash-verified

45// and each remaining Promise will be created once one of the earlier Promises resolves.) This async
46// function resolves once all `total` Promises have resolved.
47export const timesLimit = async (total: number, concurrency: number, promiseCreator: Function) => {
48 if (total > 0 && concurrency <= 0) throw new RangeError('concurrency must be positive');
49 let next = 0;
50 const addAnother = () => promiseCreator(next++).finally(() => {
51 if (next < total) return addAnother();
52 });
53 const promises = [];
54 for (let i = 0; i < concurrency && i < total; i++) {
55 promises.push(addAnother());
56 }
57 await Promise.all(promises);
58};
59
60/**
61 * An ordinary Promise except the `resolve` and `reject` executor functions are exposed as

Callers 3

promises.tsFile · 0.90
deleteRevisionsFunction · 0.90
removeMethod · 0.85

Calls 2

addAnotherFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected