utils#sleep TypeScript Examples
The following examples show how to use
utils#sleep.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.ts From exevo-pan with The Unlicense | 6 votes |
batchPromises = async <T>(
tasks: Array<() => Promise<T>>,
): Promise<T[]> => {
const results: T[] = []
for (let i = 0; i < tasks.length; i += MAX_CONCURRENT_REQUESTS) {
const currentBatch = tasks.slice(i, i + MAX_CONCURRENT_REQUESTS)
const batchResults: T[] = await Promise.all(currentBatch.map((fn) => fn()))
batchResults.forEach((result) => results.push(result))
await sleep(DELAY)
}
return results
}
Example #2
Source File: index.ts From exevo-pan with The Unlicense | 6 votes |
exponentialBackoffDelay = async (retriesLeft: number): Promise<void> => {
if (retriesLeft > 0) {
const magnitude = requests.MAX_RETRIES - retriesLeft
const exponentialDelay = BASE_DELAY ** magnitude * MILLISECONDS
tabBroadcast(`Next retry in ${exponentialDelay}ms`, 'control')
await sleep(exponentialDelay)
}
}