Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/samualtnorman/lib. A collection of common utilities I need. www.npmjs.com/package/@samual/lib
Something went wrong. Try again.
12345678910111213141516171819202122/** @example * const lock = createLock() * * const lockingFunction = () => lock(async () => { * // ... * }) */export function createLock() { let promise = Promise.resolve()
return async <T>(callback: () => Promise<T>): Promise<T> => { const oldPromise = promise let unlock!: () => void
promise = new Promise(resolve => unlock = resolve) await oldPromise
return callback().finally(unlock) }}
export default createLock