tazer
v1.0.0
Published
Tazer is a powerful NPM package designed to control API requests, ensuring they are processed one at a time. It provides a robust queueing system and includes a validation checker to verify its proper functioning.
Downloads
5
Readme
Tazer
Tazer is a powerful NPM package designed to control API requests, ensuring they are processed one at a time. It provides a robust queueing system and includes a validation checker to verify its proper functioning.
Features
- Request Queueing: Tazer efficiently queues incoming API requests and processes them sequentially, preventing overload and ensuring orderly execution.
- Promise-based API: Each request returns a Promise, allowing for easy integration with async/await syntax.
- Automatic Queue Processing: Once a request is added to the queue, Tazer automatically starts processing if it's not already doing so.
- Request Timing: Tazer logs the time between requests, helping you monitor and optimize your API usage.
- Validation Checker: A static method is provided to validate that Tazer is correctly processing requests one-by-one.
Installation
Install Tazer via NPM:
npm install tazer
Usage
- Here's a quick example of how to use Tazer:
const Tazer = require('tazer');
const tazer = new Tazer();
// Example API request function
const makeApiRequest = () => fetch('https://api.example.com/data');
// Enqueue requests
tazer.enqueue(makeApiRequest)
.then(result => console.log(result))
.catch(error => console.error(error));
tazer.enqueue(makeApiRequest)
.then(result => console.log(result))
.catch(error => console.error(error));
// Validate Tazer's operation
Tazer.validate(tazer);
API
new Tazer()
Creates a new Tazer instance.
tazer.enqueue(request)
Adds a request to the queue. Returns a Promise that resolves with the result of the request or rejects if an error occurs.
request: A function that returns a Promise (e.g., an API call).
Tazer.validate(tazerInstance)
Static method to check if Tazer is processing requests correctly.
tazerInstance: An instance of Tazer to validate.