Anti-shake function and throttle problems

Superposition problem timer

        

 

 

         Why overlay?

         Continuous when clicked, will open a lot of timers, when three seconds of time, these timers submit task to the task queue, event loop is a continuous cycle, find the task execution, no time interval.

Solution

         Re-open the current timer time, remove the front of the timer task. Continuous click, last click guarantee task execution, click open in front of the task are cleared. This solution is called anti-shake function.

Anti-shake function.

Throttle function: no matter how the user triggered Code or in accordance with certain rules and orderly execution.

For example, we click on the button once every three seconds to send the request, no matter how clicks are performed once three seconds.   

 

Guess you like

Origin www.cnblogs.com/zhangyuxinxin/p/12450892.html