fix(persistence): serialize autosave generations before queue effects
Track settings input generations so an older asynchronous secret save cannot mark a newer value durable. Commit queue snapshots before cancellation, cleanup, or pause effects so SQLite failures leave runtime processes and files unchanged.
This commit is contained in:
@@ -3,3 +3,17 @@ export function persistStateChange<T>(current: T, createNext: (current: T) => T,
|
||||
persist(next);
|
||||
return next;
|
||||
}
|
||||
|
||||
export async function commitQueueMutation<T>(
|
||||
current: T,
|
||||
createNext: (current: T) => T,
|
||||
persist: (next: T) => void,
|
||||
apply: (next: T) => void,
|
||||
effects: () => Promise<void>,
|
||||
): Promise<T> {
|
||||
const next = createNext(current);
|
||||
persist(next);
|
||||
apply(next);
|
||||
await effects();
|
||||
return next;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user