mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-01 03:53:11 +00:00
24 lines
650 B
TypeScript
24 lines
650 B
TypeScript
/**
|
|
* Runs file uploads one-by-one while holding an aggregate pending flag true
|
|
* until every file has settled (success or failure). Avoids relying on a single
|
|
* TanStack Mutation `isPending`, which can flip false when a later small file
|
|
* finishes before an earlier large one.
|
|
*/
|
|
export async function runSequentialUploads<TFile>(
|
|
files: readonly TFile[],
|
|
upload: (file: TFile) => Promise<unknown>,
|
|
setPending: (pending: boolean) => void,
|
|
): Promise<void> {
|
|
if (files.length === 0) {
|
|
return;
|
|
}
|
|
|
|
setPending(true);
|
|
try {
|
|
for (const file of files) {
|
|
await upload(file);
|
|
}
|
|
} finally {
|
|
setPending(false);
|
|
}
|
|
}
|