refactor(memory): share sync progress helpers
This commit is contained in:
38
src/memory/sync-progress.ts
Normal file
38
src/memory/sync-progress.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
export type SyncProgressState = {
|
||||
completed: number;
|
||||
total: number;
|
||||
label?: string;
|
||||
report: (update: { completed: number; total: number; label?: string }) => void;
|
||||
};
|
||||
|
||||
export function bumpSyncProgressTotal(
|
||||
progress: SyncProgressState | undefined,
|
||||
delta: number,
|
||||
label?: string,
|
||||
) {
|
||||
if (!progress) {
|
||||
return;
|
||||
}
|
||||
progress.total += delta;
|
||||
progress.report({
|
||||
completed: progress.completed,
|
||||
total: progress.total,
|
||||
label,
|
||||
});
|
||||
}
|
||||
|
||||
export function bumpSyncProgressCompleted(
|
||||
progress: SyncProgressState | undefined,
|
||||
delta = 1,
|
||||
label?: string,
|
||||
) {
|
||||
if (!progress) {
|
||||
return;
|
||||
}
|
||||
progress.completed += delta;
|
||||
progress.report({
|
||||
completed: progress.completed,
|
||||
total: progress.total,
|
||||
label,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user