https://github.com/andrewaylett/self-throttle
Helps clients to not overwhelm the services they call
https://github.com/andrewaylett/self-throttle
client nodejs sre
Last synced: about 2 months ago
JSON representation
Helps clients to not overwhelm the services they call
- Host: GitHub
- URL: https://github.com/andrewaylett/self-throttle
- Owner: andrewaylett
- License: apache-2.0
- Created: 2020-09-28T12:33:11.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2026-01-24T18:30:07.000Z (about 2 months ago)
- Last Synced: 2026-01-25T07:40:44.584Z (about 2 months ago)
- Topics: client, nodejs, sre
- Language: TypeScript
- Homepage:
- Size: 1.53 MB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Self-Throttle User Guide
As a service client, there's little point in sending requests to the service that we can be reasonably sure will fail.
Once we start seeing remote failures, we'll only send 1.2x the number of successes observed over the past minute.
Self-Throttle is Promise-based, and provides two methods for throttling calls:
```javascript
// A SelfThrottle object scopes throttling -- create one per service you call
const throttle = new SelfThrottle();
// We can throttle individual calls
// this will call the function and record the promise it returns
await throttle.attempt(() => functionReturningAPromise(123));
// We can wrap a function for re-use
const throttledFunction = throttle.wrap(functionReturningAPromise);
await throttledFunction(456);
await throttledFunction(789);
```