-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(throttle): implements throttling requests
- Loading branch information
Showing
3 changed files
with
38 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* Set a throttle. Short for `.config({ throttle: ... })` | ||
* | ||
* @function throttle | ||
* @memberof Command | ||
* @param {Number} tokensPerInterval Maximum number of tokens that can be | ||
* removed at any given moment and over the course of one interval. | ||
* @param {String|Number} interval The interval length in milliseconds, or as | ||
* one of the following strings: 'second', 'minute', 'hour', day'. | ||
* @see Osmosis.config | ||
*/ | ||
|
||
var RateLimiter = require('limiter').RateLimiter; | ||
|
||
module.exports = function (tokensPerInterval, interval) { | ||
this.instance.throttle = new RateLimiter( | ||
tokensPerInterval || 1000, | ||
interval || 1 | ||
); | ||
|
||
return this; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters