prevent double close

This commit is contained in:
Riccardo Balbo 2024-10-16 15:33:07 +02:00 committed by k00b
parent 623b69df3a
commit 4bc669c1c5
1 changed files with 10 additions and 2 deletions

View File

@ -30,7 +30,13 @@ export default function useLocalStorage ({ database = 'default', namespace = ['d
}
}, [me, database, joinedNamespace])
return [storage]
return [{
set: storage.set,
get: storage.get,
unset: storage.unset,
clear: storage.clear,
list: storage.list
}]
}
/**
@ -167,7 +173,7 @@ function newIdxDBBackend (userId, database, namespace) {
const queue = createTaskQueue()
let openConnection = null
let closed = false
const initialize = async () => {
if (!openConnection) {
openConnection = await openIdxDB(userId, database, (db) => {
@ -249,6 +255,8 @@ function newIdxDBBackend (userId, database, namespace) {
})
},
close: async () => {
if (closed) return
closed = true
queue.enqueue(async () => {
if (openConnection) await openConnection.close()
})