-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
What about a throttle object? #943
Comments
I think I would be more comfortable delegating this to a third party library (they are extremely well ironed out in lodash/underscore). Throttle is a tricky method as you have to consider timezone constraints, timeouts, various options, etc. Unless you can think of a case that would be cleaner having this functionality in async itself I think its better left to existing implementations. That said, it could be a good idea to add a related topic to the readme https://lodash.com/docs#throttle |
Hi, thanks for getting back to me, firstly, and sorry it's taken me so long to reply. In the end I just implemented a simple queue myself (queue.js) and added what I called a bottle neck on top of that (bottleNeck.js). And you're right, stuff like this is too specific to find it's way into async. I've now rolled my own modules to deal with this stuff although I keep async for the unit tests. Working with async has helped my understanding of JavaScript, which is always good. I'm grateful! Kind regards, James |
There is a bit of demand for something like this. I think the problem in #1020 could have been solved by some sort of throttled queue. |
@aearly as I described in that thread he wasn't looking for a throttle |
Ah, I might be confused. He wanted staggering of execution, which seemed like it could be accomplished with queued task functions in a throttled queue. |
Hi, yeah, I think we had this covered but thanks for the feedback. I have a queue:
And on top of that I have what I call a bottleneck, which I thought was a better name for what I wanted:
The queue allows me to enforce sequentiality on the client, the bottleneck on top allows me to 'force' tasks. Forced tasks are only executed, and executed immediately, if the underlying queue is empty. Otherwise they are discarded. The You would want tasks to add and remove files from a session to be pushed, for example, whereas periodic session update tasks you would want to be forced. async could have given me the queue but in the end I rolled my own, you know how it is. Regards, James |
Hi,
one thing that would be useful (to me at any rate) is an object similar to a queue but that rejects attempts to add tasks unless there are no tasks executing (asynchronously). Put another way, if you add a task, attempts to add further tasks will fail until the existing and only task has finished or an error occurs.
I can give a case study. Suppose you want to write a collaborative editor for the browser. You want to execute an update task whenever a key is pressed, say, or periodically in the background say every second. So if an update task is executing, others can be safely rejected.
In essence a throttle (as I call it) is a bit like queue of length at most one. In this case study it effectively throttles network activity, hence the name, and in fact also assures that that activity happens sequentially, which makes life easier, too, as you know.
Kind regards,
James
The text was updated successfully, but these errors were encountered: