功能如何限制其通话?如果过于频繁,则不应丢弃这些调用,而是在时间上排队并间隔开,间隔为X毫秒。我查看了油门和去抖动,但他们放弃了呼叫,而不是将它们排队等待将来运行。
How can a function rate-limit its calls? The calls should not be discarded if too frequent, but rather be queued up and spaced out in time, X milliseconds apart. I've looked at throttle and debounce, but they discard calls instead of queuing them up to be run in the future.
任何更好的解决方案在X毫秒间隔内设置 process()方法的队列? JS框架中是否有这样的标准实现?到目前为止,我已经查看了 underscore.js - 没有。
Any better solution than a queue with a process() method set on an X millisecond interval? Are there such standard implementations in JS frameworks? I've looked at underscore.js so far - nothing.
推荐答案虽然其他人提供的片段确实有用(我已经建立了一个图书馆基于它们),对于那些想要使用支持良好的模块的人来说,这里是首选:
While the snippets offered by others do work (I've built a library based on them), for those who want to use well-supported modules, here are the top choices:
- 热门广告限速器是限制器
- function-rate-limit 有一个简单的API可用,并且在npmjs上有很好的使用统计数据
- valvelet ,一个较新的模块,声称通过支持做得更好承诺,但尚未普及
- the most popular rate limiter is limiter
- function-rate-limit has a simple API that works, and good usage stats on npmjs
- valvelet, a newer module, claims to do an even better job by supporting promises, but hasn't gained popularity yet
更多推荐
限制JavaScript函数调用,但排队(不要丢弃调用)
发布评论