UNPKG

mutual-exclusion

Version:

Mutual Exclusion (mutex) object for JavaScript.

27 lines (23 loc) 699 B
// @flow /** * @property holdTimeout The maximum amount of time lock can be held (default: 30000). * @property key Used to scope mutex (default: a random generated value). * @property waitTimeout The maximum amount of time lock can be waited for (default: 5000). */ export type MutexConfigurationInputType = {| +holdTimeout?: number, +key?: string, +waitTimeout?: number, |}; export type LockConfigurationInputType = {| +holdTimeout?: number, +key?: string, +waitTimeout?: number, |}; export type MutexType = {| +isLocked: (key?: string) => boolean, +lock: ( routine: () => Promise<void>, lockConfigurationInput?: LockConfigurationInputType, ) => Promise<void>, |};