Skip to content

Commit

Permalink
fix: additional guard in load if write queue is busy
Browse files Browse the repository at this point in the history
  • Loading branch information
Akryum committed Sep 4, 2024
1 parent 68bf368 commit b35585d
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions packages/core/src/storage/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,14 @@ export async function useStorage<TData extends { id: string }>(mq: MoquerieInsta

if (shouldWatch) {
refreshInterval = setInterval(async () => {
if (!writeQueue.busy) {
manifest = await readManifest()
await load()
try {
if (!writeQueue.busy) {
manifest = await readManifest()
await load()
}
}
catch (e) {
console.warn('Error auto-refreshing storage', e)
}
}, 5000)
}
Expand Down Expand Up @@ -401,6 +406,9 @@ export async function useStorage<TData extends { id: string }>(mq: MoquerieInsta
try {
const item = await readFile(id, file)
newData.push(item)
if (writeQueue.busy) {
throw new Error('Write queue is busy, aborting load')
}
}
catch (e) {
console.error(e)
Expand Down

0 comments on commit b35585d

Please sign in to comment.