Skip to content

Commit c3cf935

Browse files
PR Batch Testerclaude
andcommitted
refactor(web): hold the offline queue's Web Lock on the caller's fiber
The lock callback ran the locked work with Effect.runPromiseExit, which started a separate root fiber and dropped the caller's context. The lock is now acquired and released around the work, which runs on the caller's fiber. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 4994187 commit c3cf935

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

‎apps/web/src/connection/threadTriageOutboxStore.ts‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@ import * as Effect from "effect/Effect";
66

77
const STORAGE_KEY = "t3code:thread-triage-outbox";
88

9+
/** Resolves with the release once the lock is granted, so the locked work runs on the caller's fiber. */
10+
const acquireLock = (locks: LockManager) =>
11+
Effect.tryPromise({
12+
try: () =>
13+
new Promise<() => void>((granted, rejected) => {
14+
locks
15+
.request(STORAGE_KEY, () => new Promise<void>((release) => granted(() => release())))
16+
.catch(rejected);
17+
}),
18+
catch: (cause) => new ThreadTriageOutboxStorageError({ cause }),
19+
});
20+
921
/** Kept out of the environment cache so clearing cached data keeps unsynced settles and snoozes. */
1022
export const browserThreadTriageOutboxStore = makeThreadTriageOutboxStore({
1123
read: Effect.try({
@@ -25,8 +37,9 @@ export const browserThreadTriageOutboxStore = makeThreadTriageOutboxStore({
2537
cause: new Error("Offline thread changes require Web Locks. Use HTTPS or localhost."),
2638
}),
2739
)
28-
: Effect.tryPromise({
29-
try: () => navigator.locks.request(STORAGE_KEY, () => Effect.runPromiseExit(effect)),
30-
catch: (cause) => new ThreadTriageOutboxStorageError({ cause }),
31-
}).pipe(Effect.flatten),
40+
: Effect.acquireUseRelease(
41+
acquireLock(navigator.locks),
42+
() => effect,
43+
(release) => Effect.sync(release),
44+
),
3245
});

0 commit comments

Comments
 (0)