npm.io
1.0.6 • Published 3 years ago

@keeex/axios-concurrency

Licence
MIT
Version
1.0.6
Deps
0
Size
5 kB
Vulns
0
Weekly
0

Axios Concurrency Manager

Get control of concurrent requests of any axios instance. Implemented using axios interceptors

Fork information

This project was forked by KeeeX in order to fix a few issues and keep dependencies updated.

Installing

$ npm install axios-concurrency

Example

const { ConcurrencyManager } = require("axios-concurrency");
const axios = require("axios");

let api = axios.create({
  baseURL: "http://mypublicapi.com"
});

// a concurrency parameter of 1 makes all api requests secuential
const MAX_CONCURRENT_REQUESTS = 5;

// init your manager.
const manager = ConcurrencyManager(api, MAX_CONCURRENT_REQUESTS);

// requests will be sent in batches determined by MAX_CONCURRENT_REQUESTS
Promise.all(manyIds.map(id => api.get(`/test/${id}`)))
  .then(responses => {
    // ...
  });

// to stop using the concurrency manager.
// will eject the request and response handlers from your instance
manager.detach()

License

MIT

Keywords