prevent double close
This commit is contained in:
parent
623b69df3a
commit
4bc669c1c5
|
@ -30,7 +30,13 @@ export default function useLocalStorage ({ database = 'default', namespace = ['d
|
||||||
}
|
}
|
||||||
}, [me, database, joinedNamespace])
|
}, [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()
|
const queue = createTaskQueue()
|
||||||
|
|
||||||
let openConnection = null
|
let openConnection = null
|
||||||
|
let closed = false
|
||||||
const initialize = async () => {
|
const initialize = async () => {
|
||||||
if (!openConnection) {
|
if (!openConnection) {
|
||||||
openConnection = await openIdxDB(userId, database, (db) => {
|
openConnection = await openIdxDB(userId, database, (db) => {
|
||||||
|
@ -249,6 +255,8 @@ function newIdxDBBackend (userId, database, namespace) {
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
close: async () => {
|
close: async () => {
|
||||||
|
if (closed) return
|
||||||
|
closed = true
|
||||||
queue.enqueue(async () => {
|
queue.enqueue(async () => {
|
||||||
if (openConnection) await openConnection.close()
|
if (openConnection) await openConnection.close()
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue