Skip to content

Commit 4978123

Browse files
committed
refactor: use SyncError instead of defects
1 parent 4dbb186 commit 4978123

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

packages/@livestore/common/src/sync/ClientSessionSyncProcessor.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export const makeClientSessionSyncProcessor = ({
9090
const eventDef = getEventDef(schema, name)
9191
const nextNumPair = EventSequenceNumber.nextPair({
9292
seqNum: baseEventSequenceNumber,
93-
isClient: eventDef.eventDef.options.clientOnly
93+
isClient: eventDef.eventDef.options.clientOnly,
9494
})
9595
baseEventSequenceNumber = nextNumPair.seqNum
9696
return new LiveStoreEvent.EncodedWithMeta(
@@ -115,13 +115,13 @@ export const makeClientSessionSyncProcessor = ({
115115
)
116116

117117
if (mergeResult._tag === 'unexpected-error') {
118-
return yield* Effect.die(new Error(`Unexpected error in client-session-sync-processor: ${mergeResult.message}`))
118+
return yield* new SyncError({ cause: mergeResult.message })
119119
}
120120

121121
if (TRACE_VERBOSE) yield* Effect.annotateCurrentSpan({ mergeResult: JSON.stringify(mergeResult) })
122122

123123
if (mergeResult._tag !== 'advance') {
124-
return yield* Effect.die(new Error(`Expected advance, got ${mergeResult._tag}`))
124+
return yield* new SyncError({ cause: `Expected advance, got ${mergeResult._tag}` })
125125
}
126126

127127
syncStateRef.current = mergeResult.newSyncState
@@ -197,7 +197,7 @@ export const makeClientSessionSyncProcessor = ({
197197

198198
// NOTE We need to lazily call `.pull` as we want the cursor to be updated
199199
yield* Stream.suspend(() =>
200-
clientSession.leaderThread.events.pull({ cursor: syncStateRef.current.upstreamHead }),
200+
clientSession.leaderThread.events.pull({ cursor: syncStateRef.current.upstreamHead }),
201201
).pipe(
202202
Stream.tap(({ payload }) =>
203203
Effect.gen(function* () {
@@ -221,7 +221,7 @@ export const makeClientSessionSyncProcessor = ({
221221
}
222222

223223
syncStateRef.current = mergeResult.newSyncState
224-
syncStateUpdateQueue.offer(mergeResult.newSyncState).pipe(Effect.runSync)
224+
yield* syncStateUpdateQueue.offer(mergeResult.newSyncState)
225225

226226
if (mergeResult._tag === 'rebase') {
227227
span.addEvent('merge:pull:rebase', {
@@ -346,7 +346,7 @@ export interface ClientSessionSyncProcessor {
346346
{
347347
writeTables: Set<string>
348348
},
349-
never
349+
SyncError
350350
>
351351
boot: Effect.Effect<void, UnexpectedError, Scope.Scope>
352352
/**

0 commit comments

Comments
 (0)