/
githubmirror
/
novu
Обзор
Документация
Войти
/
githubmirror
/
novu
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
next
packages/react/src/utils/requestLock.ts
33 строки
746 B
Paweł Tymczuk
fix(js,react): when web locks not available then dont broadcast messages fixes NV-8425 (#12170)
31 июл 2026, 17:07
Не верифицирован
31 июл 2026, 17:07
8978699
Код
Авторство
О чём код?
export function isWebLocksSupported(): boolean { return typeof navigator !== 'undefined' && 'locks' in navigator && !!navigator.locks; } export function requestLock(id: string, cb: (id: string) => void) { // Check if the Lock API is available if (!isWebLocksSupported()) { // If Lock API is not available, immediately invoke the callback and return a no-op function cb(id); return () => {}; } let isFulfilled = false; let promiseResolve: () => void; const promise = new Promise<void>((resolve) => { promiseResolve = resolve; }); navigator.locks.request(id, () => { if (!isFulfilled) { cb(id); } return promise; }); return () => { isFulfilled = true; promiseResolve(); }; }