Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including glouton with all npm packages installed. Try it out:

var glouton = require("glouton")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

glouton v1.0.0

Like Promise.all but with retry and rate limit

Glouton

Ever wanted to send a lot of requests concurrently to an API but got bothered with API limits ? Or failing requests ?

Example with fetch

import glouton from 'glouton';

const fetchNoLimit = glouton(fetch, {

  concurrency: 400, // 400 requests at a time

  validateResponse: r => {

    // if limit has been reached, we wait 1 second
    if (!r.ok && r.headers.get('x-ratelimit') === 0) {
      return 1000;
    }
    
    // if request has failed, we'll try again later
    if (!r.ok) {
      return 0;
    }

    // everything is ok, we shall proceed
    return true;
  },

});

[/* some ids */].forEach(() => {
  fetchNoLimit('http://someapi.on.the.web')
  .then((r) => {
    console.log("Here's my response!", r);
  });
});
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free