parent
7a84ff4a74
commit
ec41e91388
@ -0,0 +1,18 @@ |
|||||||
|
export const debouncing = async (time: number = 1000) => { |
||||||
|
return new Promise((resolve, reject) => { |
||||||
|
const timerId = setTimeout(() => { |
||||||
|
resolve(true) |
||||||
|
}, time) |
||||||
|
const listener = (event: any) => { |
||||||
|
if (event.detail === timerId) { |
||||||
|
return |
||||||
|
} |
||||||
|
clearTimeout(timerId) |
||||||
|
reject(new Error('locked!!!' + timerId)) |
||||||
|
document.removeEventListener('debiuncing.clean', listener); |
||||||
|
} |
||||||
|
document.addEventListener('debiuncing.clean', listener) |
||||||
|
const event = new CustomEvent('debiuncing.clean', { detail: timerId }); |
||||||
|
document.dispatchEvent(event); |
||||||
|
}) |
||||||
|
} |
Loading…
Reference in new issue