UNPKG

1.49 kBSource Map (JSON)View Raw
1{"version":3,"file":"mutex-63f09c81.cjs","sources":["../mutex.js"],"sourcesContent":["/**\n * Mutual exclude for JavaScript.\n *\n * @module mutex\n */\n\n/**\n * @callback mutex\n * @param {function():void} cb Only executed when this mutex is not in the current stack\n * @param {function():void} [elseCb] Executed when this mutex is in the current stack\n */\n\n/**\n * Creates a mutual exclude function with the following property:\n *\n * ```js\n * const mutex = createMutex()\n * mutex(() => {\n * // This function is immediately executed\n * mutex(() => {\n * // This function is not executed, as the mutex is already active.\n * })\n * })\n * ```\n *\n * @return {mutex} A mutual exclude function\n * @public\n */\nexport const createMutex = () => {\n let token = true\n return (f, g) => {\n if (token) {\n token = false\n try {\n f()\n } finally {\n token = true\n }\n } else if (g !== undefined) {\n g()\n }\n }\n}\n"],"names":[],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,WAAW,GAAG,MAAM;AACjC,EAAE,IAAI,KAAK,GAAG,KAAI;AAClB,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC,KAAK;AACnB,IAAI,IAAI,KAAK,EAAE;AACf,MAAM,KAAK,GAAG,MAAK;AACnB,MAAM,IAAI;AACV,QAAQ,CAAC,GAAE;AACX,OAAO,SAAS;AAChB,QAAQ,KAAK,GAAG,KAAI;AACpB,OAAO;AACP,KAAK,MAAM,IAAI,CAAC,KAAK,SAAS,EAAE;AAChC,MAAM,CAAC,GAAE;AACT,KAAK;AACL,GAAG;AACH;;;;;;;;;;"}
\No newline at end of file