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.
20 lines
514 B
TypeScript
20 lines
514 B
TypeScript
export function persistStateChange<T>(current: T, createNext: (current: T) => T, persist: (next: T) => void): T {
|
|
const next = createNext(current);
|
|
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;
|
|
}
|