当前位置:网站首页>Anti shake and throttling
Anti shake and throttling
2022-06-10 21:33:00 【It's Luoluo】
Both anti shake and throttling are used to solve the problem that the front-end events are too frequent , Considering the utilization of resources and the burden of equipment , You need to control the number of requests . The purpose of anti shake and throttling is the same , But it's not the same way .
Shake proof
Anti shake is only responding to the last event , Just tell , Suppose an event has been triggered , Start timing , If in a period of time , If this event is triggered again , Restart the clock , Until the timing is complete , Responding to events .
function fangdou(fn,delay){
let timer = null;
return function(){
if(timer)
clearTimeout(timer);
timer = setTimeout(()=>{
fn.call(this);
},delay)
}
}
Use this function directly when using ,fn Is the response event ,delay It's the timing .
throttle
Throttling controls the time interval between two response events , I promise that within this period of time , Will no longer respond to this event , Time goes by , You can respond to this event again .
function jieliu(fn,delay) {
let ready = true;
return function (){
if(ready){
fn.call(this);
ready = false;
setTimeout(()=>{
ready = true;
},delay)
}
}
}
Use this function directly when using ,fn Is the response event ,delay Is the time interval between two corresponding .
边栏推荐
- Realize OSD reverse color on YUV image according to background color
- Interview Essentials - basic knowledge of synchronized underlying principles
- A small case with 666 times performance improvement illustrates the importance of using indexes correctly in tidb
- LeetCode:497. Random points in non overlapping rectangles -- medium
- Redis集群配置
- H.264中NALU、RBSP、SODB的关系
- User defined date component. The left and right buttons control forward or backward year, month, week and day turning
- Shell implements SSH login and executes commands
- Leetcode advanced road - 167 Sum of two numbers II - input ordered array
- 1、 Vulkan develops theoretical fundamentals
猜你喜欢

Pytorch deep learning -- convolution operation and code examples

设计多层PCB板需要注意哪些事项?

Understanding deep learning attention

User defined date component. The left and right buttons control forward or backward year, month, week and day turning

异步、线程池(CompletableFuture)

CET-6 - Business English - the last recitation before the test

信号与系统复习1

Magic tower game implementation source code and level generation

C language -- 3 variables for beginners

【北大青鸟昌平校区】职教与普教协调发展,今年的中考会容易吗?
随机推荐
Nodejs: official document 3 Dgram stream
Serial Print() and serial The difference of write() function, and the problem of hexadecimal and string sending and receiving format in serial port communication and detailed explanation of the conver
72. 编辑距离 ●●●
【无标题】破目
H265 Nalu类型判断及 sps 数据解析
北大青鸟昌平校区:高中学历可以学UI吗?
Is it safe to buy funds on mobile phones? Will the principal be swallowed?
数据库系统概论 ---- 第一章 -- 绪论(重要知识点)
Magic tower game implementation source code and level generation
Explain in detail the arithmetic operators related to matrix operation in MATLAB (addition, subtraction, multiplication, division, point multiplication, point division, power)
蛮力法/u到v是否存在简单路径
微积分复习1
Game compatibility test (general scheme)
App test case
Practical | how to use burp suite for password blasting!
Kcon 2022 topic public selection is hot! Don't miss the topic of "favorite"
Connexion MySQL errorcode 1129, State hy000, Host 'xxx' is Blocked because of many Connection Errors
冷酸灵,一个国产品牌IPO的30年曲折史
C language -- 3 variables for beginners
[computer use] how to set software startup without auto startup