Fix daft bug - promises weren't racing

This commit is contained in:
Oliver Blanthorn 2020-02-29 19:04:02 +00:00
parent 63d2b4ab9e
commit 6f6c9e0cd0
No known key found for this signature in database
GPG key ID: 2BB8C36BB504BFF3

View file

@ -17,9 +17,11 @@ export async function acquire(lockname: string, timeout= 2000) {
DESIRED_LOCKS[lockname] = time
await Promise.all([
browser.runtime.sendMessage({type: "lock", command: "acquire", args: [lockname, time, ID]}),
messageAllTabs("lock", "acquire", [lockname, time, ID]),
await Promise.race([
Promise.all([
browser.runtime.sendMessage({type: "lock", command: "acquire", args: [lockname, time, ID]}),
messageAllTabs("lock", "acquire", [lockname, time, ID]),
]),
new Promise(resolve => setTimeout(resolve, timeout)), // Take lock anyway after timeout
])