New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

request-rate-clock

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

request-rate-clock - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

CHANGELOG.md

2

package.json
{
"name": "request-rate-clock",
"version": "0.1.0",
"version": "0.1.1",
"description": "Rateclock provides a clock mechanism to work with api rate limits",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -1,5 +0,4 @@

# SavePromise
# Request Rate Clock
SavePromise is a very small library that allows you to handle saving of data in a promise-like way.
If you have json data you want to save and it is modified, saved and modified again (so you would save it again), you could probably have two save operations at the same time. This library allows you to handle this situation. You can save your data and if it is already saving, it waits for the first save to finish and then saves the data again. It also schudules only one save operation if you save your data multiple times in a short period of time, so you don't have to worry about saving your data too often.
This package provides a clock that can be used to limit the rate of requests to a server. It is useful for rate limiting requests to a server, for example to prevent a server from being overwhelmed by too many requests or using rate-limited APIs like the GitHub API, Spotify API, etc.

@@ -9,3 +8,3 @@ ## Installation

```bash
npm install savepromise
npm install request-rate-clock
```

@@ -16,36 +15,16 @@

```javascript
import SavePromise from "savepromise";
import RateClock from "request-rate-clock";
const savePromise = SavePromise(() => {
// function that saves your data
});
const clock = RateClock.create(5, 1000); // Allow 5 requests per second
//save using:
savePromise.save(data);
(async () => {
for (let i = 0; i < 1000; i++) {
await clock.acquire();
console.log("Request", i + 1);
}
})().catch(console.error);
```
In the above example, the data is saved only once. If you are saving your data multiple times in a short period of time, the true power of this library comes to light. If you save your data multiple times, it is saved only once. If you save your data again, it is saved again after the first save is finished.
So it will optimize your saving operations.
## API
So if you have this code:
```javascript
import SavePromise from "savepromise";
const savePromise = SavePromise(() => {
// function that saves your data
});
//save using:
savePromise.save(data);
// modify data
savePromise.save(data);
// modify data
savePromise.save(data);
// modify data
savePromise.save(data);
// modify data
savePromise.save(data);
```
there will only be two save operations.
### `RateClock.create(rate: number, interval: number): RateClock`
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc