当前位置:网站首页>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 .
边栏推荐
- 防抖和节流
- H.264中NALU、RBSP、SODB的关系
- LeetCode:1037. Effective boomerang - simple
- Brute force method / adjacency table depth first directed weighted graph undirected weighted graph
- Leetcode advanced path - reverse string
- 蛮力法/任务分配
- 详解MATLAB中与矩阵运算有关的算术运算符(加、减、乘、除、点乘、点除、乘方)
- 视频监控系统存储控件,带宽计算方法
- Leetcode advanced path - delete duplicates in the sorting array
- 01js基础 null与undefined区别 类型转换 == 代码块 逻辑运算符
猜你喜欢

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

Quick start to elastic job, three minutes to experience distributed scheduled tasks

Talk about server performance optimization ~ (recommended Collection)

What is the difference between localhost and 127.0.0.1?

Explain in detail the arithmetic operators related to matrix operation in MATLAB (addition, subtraction, multiplication, division, point multiplication, point division, power)

Redis cache penetration

冷酸灵,一个国产品牌IPO的30年曲折史

微积分复习1

面试必备——synchronized底层原理的基础知识

連接mysql報錯 errorCode 1129, state HY000, Host ‘xxx‘ is blocked because of many connection errors
随机推荐
A small case with 666 times performance improvement illustrates the importance of using indexes correctly in tidb
Record today's MySQL failures
Leetcode advanced path - Search insertion location
Heap sorting and hardening heap code for memory
CET-6 - Business English - the last recitation before the test
Identity and access management (IAM)
【无标题】破目
LeetCode:1037. Effective boomerang - simple
leetcode 划分数组使最大差为 K
LeetCode 进阶之路 - 字符串中的第一个唯一字符
LeetCode:497. Random points in non overlapping rectangles -- medium
[computer use] how to set software startup without auto startup
设计多层PCB板需要注意哪些事项?
Quick start to elastic job, three minutes to experience distributed scheduled tasks
Brute force method /k integers out of 1~n integers
Codeforces Round #798 (Div. 2)
LeetCode 进阶之路 - 加一
堆排序与加强堆代码 用于记忆
What is the difference between localhost and 127.0.0.1?
C language -- 3 variables for beginners