Optimize base64 storage in files to support concurrent storage (#2856)

* fix: variables check

* remove log

* perf: file img saved

* update doc
This commit is contained in:
Archer
2024-10-08 12:58:33 +08:00
committed by GitHub
parent dd3a1b910b
commit f6c5695df4
19 changed files with 156 additions and 80 deletions

View File

@@ -8,3 +8,24 @@ export const retryRun = <T>(fn: () => T, retry = 2): T => {
throw error;
}
};
export const batchRun = async <T>(arr: T[], fn: (arr: T) => any, batchSize = 10) => {
const batchArr = new Array(batchSize).fill(null);
const result: any[] = [];
const batchFn = async () => {
const data = arr.shift();
if (data) {
result.push(await fn(data));
return batchFn();
}
};
await Promise.all(
batchArr.map(async () => {
await batchFn();
})
);
return result;
};