Guard fallback pulls after abort
This commit is contained in:
@@ -76,6 +76,8 @@ const pullOneWithFallback = async (
|
|||||||
signal: AbortSignal,
|
signal: AbortSignal,
|
||||||
onEvent?: (event: TrustedEvent) => void,
|
onEvent?: (event: TrustedEvent) => void,
|
||||||
) => {
|
) => {
|
||||||
|
if (signal.aborted) return
|
||||||
|
|
||||||
const cachedEvents = repository.query([filter]).filter(isSignedEvent)
|
const cachedEvents = repository.query([filter]).filter(isSignedEvent)
|
||||||
const since = last(cachedEvents.slice(10))?.created_at || 0
|
const since = last(cachedEvents.slice(10))?.created_at || 0
|
||||||
|
|
||||||
@@ -93,7 +95,7 @@ const pullOneWithFallback = async (
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// If visibility flips while the negentropy diff is opening, skip the fallback path and let teardown win.
|
// If teardown wins while the diff is opening, skip the fallback path and let cleanup stay in control.
|
||||||
const diff = new Difference({relay: url, filter, events: cachedEvents, signal})
|
const diff = new Difference({relay: url, filter, events: cachedEvents, signal})
|
||||||
|
|
||||||
diff.on(DifferenceEvent.Error, () => {
|
diff.on(DifferenceEvent.Error, () => {
|
||||||
@@ -129,6 +131,8 @@ const listen = ({url, signal, filters, onEvent}: SyncOpts) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const pullAndListen = (options: SyncOpts) => {
|
const pullAndListen = (options: SyncOpts) => {
|
||||||
|
if (options.signal.aborted) return
|
||||||
|
|
||||||
pullWithFallback(options)
|
pullWithFallback(options)
|
||||||
listen(options)
|
listen(options)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user