Switch state.ts to using lock with timeout

This commit is contained in:
Oliver Blanthorn 2020-02-29 19:44:00 +00:00
parent 84d258c293
commit fae68a0df6
No known key found for this signature in database
GPG key ID: 2BB8C36BB504BFF3

View file

@ -58,9 +58,7 @@ const state = (new Proxy(overlay, {
/** Persist sets to storage "immediately" */
set(target, property, value) {
(async () => {
await locks.acquire("state")
locks.withlock("state", async () => {
logger.debug("State changed!", property, value)
target[property] = value
browser.storage.local.set({ state: target } as any)
@ -74,10 +72,7 @@ const state = (new Proxy(overlay, {
// I haven't had time to get my head around them
browser.runtime.sendMessage({type: "state", command: "stateUpdate", args: [{state: target}]}),
])
// Release named lock
locks.release("state")
})()
})
return true
},