|
|
@ -1,5 +1,11 @@ |
|
|
|
import { useStorage, useTimeoutFn } from '@vueuse/core' |
|
|
|
import { useStorage, useTimeoutFn } from '@vueuse/core' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export class SharedExecutionError extends Error { |
|
|
|
|
|
|
|
constructor(message?: string) { |
|
|
|
|
|
|
|
super(message) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
interface SharedExecutionOptions { |
|
|
|
interface SharedExecutionOptions { |
|
|
|
timeout?: number // Maximum time a lock can be held before it's considered stale - default 5000ms
|
|
|
|
timeout?: number // Maximum time a lock can be held before it's considered stale - default 5000ms
|
|
|
|
storageDelay?: number // Delay before reading from storage to allow for changes to propagate - default 50ms
|
|
|
|
storageDelay?: number // Delay before reading from storage to allow for changes to propagate - default 50ms
|
|
|
@ -102,7 +108,7 @@ export function useSharedExecutionFn<T>(key: string, fn: () => Promise<T> | T, o |
|
|
|
() => { |
|
|
|
() => { |
|
|
|
timedOut = true |
|
|
|
timedOut = true |
|
|
|
localStorage.removeItem(storageLockKey) |
|
|
|
localStorage.removeItem(storageLockKey) |
|
|
|
reject(new Error(`Timeout waiting for result on key ${key}`)) |
|
|
|
reject(new SharedExecutionError(`Timeout waiting for result on key ${key}`)) |
|
|
|
}, |
|
|
|
}, |
|
|
|
currentLock?.timestamp ? timeout - (Date.now() - currentLock.timestamp) : timeout, |
|
|
|
currentLock?.timestamp ? timeout - (Date.now() - currentLock.timestamp) : timeout, |
|
|
|
) |
|
|
|
) |
|
|
|