You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
677 B
18 lines
677 B
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);
|
|
})
|
|
}
|
|
|