/
githubmirror
/
ionic-framework
Обзор
Документация
Войти
/
githubmirror
/
ionic-framework
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
core/src/utils/lock-controller.ts
35 строк
1013 B
Shawn Taylor
fix(overlays): prevent overlays from getting stuck open (#28069)
31 авг 2023, 19:30
Не верифицирован
31 авг 2023, 19:30
584e9d3
Код
Авторство
О чём код?
/** * Creates a lock controller. * * Claiming a lock means that nothing else can acquire the lock until it is released. * This can momentarily prevent execution of code that needs to wait for the earlier code to finish. * For example, this can be used to prevent multiple transitions from occurring at the same time. */ export const createLockController = () => { let waitPromise: Promise<void>; /** * When lock() is called, the lock is claimed. * Once a lock has been claimed, it cannot be claimed again until it is released. * When this function gets resolved, the lock is released, allowing it to be claimed again. * * @example ```tsx * const unlock = await this.lockController.lock(); * // do other stuff * unlock(); * ``` */ const lock = async () => { const p = waitPromise; let resolve!: () => void; waitPromise = new Promise((r) => (resolve = r)); if (p !== undefined) { await p; } return resolve; }; return { lock, }; };