限制JavaScript函数调用,但排队(不要丢弃调用)

编程入门 行业动态 更新时间:2024-10-27 23:27:30
本文介绍了限制JavaScript函数调用,但排队(不要丢弃调用)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

功能如何限制其通话?如果过于频繁,则不应丢弃这些调用,而是在时间上排队并间隔开,间隔为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函数调用,但排队(不要丢弃调用)

本文发布于:2023-11-23 04:01:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1620011.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   JavaScript

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!