Bucket Decorator
Bucket Decorator is a npm module for help you to use safe web services or other stuff without getting api limit error (Too many requests)
- Intended to use with webServices with traffic policy with Leaky Bucket algorithm
- No need to change your current implementation, just decorate used methods
- Magic
Requirements
reflect-metadata
module
Installation
npm install bucket-decorator
Usage
- Import the module:
;
- Decorate your method:
... @Bucket ... ...
API Reference
@Bucket.Limiter(options: BucketOptionsInterface)
You can decorate any method
Property | type | Default value | Description |
---|---|---|---|
limit | number | 100 | Maxim 'bucket' size. Method calls what 'get' into bucket are executed instantly. Other ones are in queue. |
leakRate | number | 10 | Leak rate for your bucket. Every second 'bucket' will have place for more leakRate calls. |
limitKey | string | '' | Is optional. You can have multiple 'buckets' with different 'names'. |
@Bucket.LimitKey()
You can decorate any string propery of your method. This will override BucketOptionsInterface.limitKey
option
Example
; ; @Bucket console; async { let testInstance = ; for let i = 0; i < 100; i++ await testInstance; };
Building
npm install
oryarn
npm run start
oryarn start
Changelog
1.0.2
- Add default values for BucketOptionsInterface
- Fix queue for function calls