Comments (6)
Hi, is this exactly what's throttleAsync is for?
from utils-decorators.
The use case is rather to limit calls to a remote API which allows for, say, 10 calls per second.
With throttleAsync there is no way to set the desired throughput, and setting the limit to 10 would only lead to rejections from the API if one of the calls take less than a second to complete.
from utils-decorators.
Maybe I am missing something. For a given limit, the throttleAsync decorator will invoke the decorated method just for the allowed amount of times. Once one of the promises will be resolved the next call in the queue will be invoked. This basically means that there won't be any rejections. Once the amount of calls will reach to the limit the new calls will be queued.
https://vlio20.github.io/utils-decorators/#throttleAsync
from utils-decorators.
Apologies if that wasn't clear 😅 Here's some pseudocode which might help a bit:
getTwitterData(): Promise<Response> {
return await fetch("https://api.twitter.com/tweets/20")
//some api endpoints that allows 10 calls per second
//this resolves only in a few milliseconds
}
// this ensures that only 10 calls per second are made, should return 200 OK
@leakyBucket({
timeSpanMs: 1000,
allowedCalls: 10,
})
getTwitterData(): Promise<Response> {…}
// this does not prevent more than 10 calls per second, subsequent calls will return 429 Too Many Requests
@throttleAsync(10)
getTwitterData(): Promise<Response> {…}
from utils-decorators.
Good point, throttleAsync will prevent that the number of concurrent call will acceed the specified number of calls it totally ignores the time perspective.
Great use-case. I would love to add it to the library.
from utils-decorators.
@vpctorr would you like to submit a PR?
from utils-decorators.
Related Issues (20)
- move target to es6 HOT 1
- Cache burst for memoize/memoizeAsync HOT 10
- "utils-decorators" has no exported member 'delegatify'. HOT 6
- throttle-async is not functioning as expected HOT 1
- AllDefined decorator
- update dependencies
- Timer, to clear the memory HOT 6
- Disable Caching for test envs HOT 6
- Add support to gettings the method name or expirationTimeMs in cach HOT 9
- [timeout decorator] Should catch the original exception if the method throw an error before timeout HOT 1
- debounce should support multi instances HOT 3
- Update dependencies HOT 1
- Provide context to the keyResolver function (target and propertyName) HOT 5
- Hot cache HOT 3
- Use of mutation testing in utils-decorators - Help needed HOT 2
- update packages
- missing await on asycMemoyze
- Request for New Feature: Enhancing Decorator Functionality with Queuing Mechanism HOT 1
- Fix delegate default serialization with many args HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from utils-decorators.