@8ms/helpers 2.2.24 → 2.2.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.yarn/install-state.gz
CHANGED
|
Binary file
|
package/package.json
CHANGED
package/util/promiseChunks.d.ts
CHANGED
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
* Chunk a queue of promises into controlled chunks to prevent overloading.
|
|
3
3
|
* https://stackoverflow.com/a/53964407
|
|
4
4
|
*/
|
|
5
|
-
export declare const promiseChunks: (promises: Promise<any>[], size: number, sleepSeconds?: number) => Promise<any[]>;
|
|
5
|
+
export declare const promiseChunks: (promises: Promise<any>[], size: number, sleepSeconds?: number, callbackFunction?: Function) => Promise<any[]>;
|
package/util/promiseChunks.js
CHANGED
|
@@ -4,13 +4,17 @@ import { sleep } from "./sleep";
|
|
|
4
4
|
* Chunk a queue of promises into controlled chunks to prevent overloading.
|
|
5
5
|
* https://stackoverflow.com/a/53964407
|
|
6
6
|
*/
|
|
7
|
-
export const promiseChunks = async (promises, size, sleepSeconds = 0) => {
|
|
7
|
+
export const promiseChunks = async (promises, size, sleepSeconds = 0, callbackFunction) => {
|
|
8
8
|
const batches = chunk(promises, size);
|
|
9
9
|
let results = [];
|
|
10
10
|
while (batches.length) {
|
|
11
11
|
const batch = batches.shift();
|
|
12
12
|
const result = await Promise.all(batch);
|
|
13
13
|
results.push(result);
|
|
14
|
+
// If there is a process to do with each chunk
|
|
15
|
+
if (callbackFunction) {
|
|
16
|
+
await callbackFunction(result);
|
|
17
|
+
}
|
|
14
18
|
await sleep(sleepSeconds);
|
|
15
19
|
}
|
|
16
20
|
return flatten(results);
|