当前位置:网站首页>Anti shake and throttling
Anti shake and throttling
2022-04-23 08:05:00 【Pen drawing Acacia】
Shake proof : The problem to be solved is when an event is triggered multiple times within a time interval , It's only going to be executed once
throttle : The solution is to reduce the trigger frequency for a period of time
1: The function will only trigger once in a specified time , Specific implementation method
When the function is triggered for the first time , Delay delay Time execution , If in delay The function is triggered again within a time period , Then start over
timing
If delay The function is not triggered within the time period , Then execute the function
function bunde(fn ,depaly)
{
let timetar=null;
return function()
{
if(timetar)
{
clearTimeout(timetar);
}
timetar=setTimeout(fn,depaly);
}
}
throttle :
The problem with anti shake is , Continuously trigger events in a short time , Callback functions never execute .
The idea of saving money : Continuously trigger events in a short time , The callback function will only execute within the specified interval .
function throttle(fn, delay) {
let timer = null;
return function() {
if (timer) return false
timer = setTimeout(() => {
fn()
timer = null
}, delay)
}
}
版权声明
本文为[Pen drawing Acacia]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230624332804.html
边栏推荐
猜你喜欢
Upload labs range practice
sentinel集成nacos动态更新数据原理
Ctf-misc learning from start to give up
《内网安全攻防:渗透测试实战指南》读书笔记(五):域内横向移动分析及防御
Simplify exporting to SVG data files and all images in SVG folder
雲計算技能大賽 -- openstack私有雲環境 第一部分
Go语学习笔记 - 结构体 | 从零开始Go语言
Export all SVG files in the specified path into pictures in PNG format (thumbnail or original size)
C # control the camera, rotate and drag the observation script (similar to scenes observation mode)
Feign源码分析
随机推荐
Intranet penetration series: icmpsh of Intranet tunnel
Intranet penetration series: ICMP of Intranet tunnel_ Tran
Ctf-misc learning from start to give up
读书笔记
Talk about the essence of interface idempotent and consumption idempotent
Research on software security based on NLP (2)
【编程实践/嵌入式比赛】嵌入式比赛学习记录(二):基于TCP的图片流传输
TA notes of Zhuang understand (VII) < Lambert + Phong + shadow + 3evcolor + Ao >
How to present your digital portfolio: suggestions from creative recruiters
Intranet penetration series: dnscat2 of Intranet tunnel
Link to some good tutorials or notes about network security and record them
Chapter IV intangible assets
面试学习路线
Go语学习笔记 - 数组 | 从零开始Go语言
FUEL: Fast UAV Exploration using Incremental Frontier Structure and Hierarchical Planning
MYSQL——第一章节(数据类型2)
Reptile learning notes, learning reptile, read this article is enough
linux下mysql数据库备份与恢复(全量+增量)
Personality charm of high paid it workers
GUI,CLI与Unix哲学