npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ya_myn/request-limiter

v2.0.3

Published

Simple request limiter that allows you to control the number of simultaneous request to any resource

Downloads

15

Readme

request-limiter 2.0.0

onix

Simple request limiter that allows you to control the number of simultaneous request to any resource with cashe (use 'node-cashe')

Install

npm i request-limiter

Examples

Require module

const ReqLimiter = require('request-limiter').getInstance('myInstance', options);

ReqLimiter.getInstance(instance, options)

Get or create instance Returns: instance of ReqLimiter

Parameters

| Name | Type | Description | Required | | -------- | -------- | -------------------------------- | -------- | | instance | string | ReqLimiter instances name |true | | options | object` | ReqLimiter configuration options | false |

options properties

| Name | Type | Description | default | | ------------------- | ---------- | -------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------- | | maxAttempts | number | Maximum number of request attempts for one function | 42 | | maxRepeatAttempts | number | Maximum number of attempts to request a request after receiving an error from the remote resource about exceeding the limit | 6 | | checkDelay | number | The amount of time in millisecond after which the limiter will make a new attempt to add the request to the queue | 1200 | | maxOneTimeReq | number | The number of request that can be executed simultaneously in one port | 6 | | clientName | string | The name to be passed to the callback function in the reqWithCheck method | client | | limitErrorValidator | function | A simple function that checks whether an error sent from a remote resource belongs to an error exceeding the request limit returns a boolean | error => error.code === 403 | | ReqLimitError | Error | Error class or classes that extend it. allows to give a custom error to the client | ReqLimitError |

ReqLimiter.haveConnect(port)

checks if a port exists and if there is cached data for it Returns: any

| Name | Type | Description | Required | | ---- | -------- | --------------------------------------- | -------- | | port | string | name of the port you would like, of use | true |

const isConnect = ReqLimiter.haveConnect('myPort');

ReqLimiter.setClient(port, client)

set client data for your port Returns: void

| Name | Type | Description | Required | | ------ | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | | port | string | name of the port you would like, of use | true | | client | any | any information you want to saved that it will be passed as a parameter named <ReqLimiter. clientName> for the callback in the reqWithCheck method | true |

ReqLimiter.setClient('myPort', { accessToken: 'myAccessToken' });

ReqLimiter.reqWithCheck(port, cb, args, attempts)

Method that takes a function that needs to be queued for a given port

Returns: cb call results

| Name | Type | Description | Required | | -------- | ---------- | ------------------------------------------------------------- | -------- | | port | string | name of the port you would like, of use | true | | cb | function | callback function, that need add to port que | true | | args | object | arguments for callback function | false | | attempts | number | The number of attempts that have already been made, default 0 | false |

const fetchToImage = ({ client, id }) => {
    return myFetcher('url', { accessToken: client.accessToken, id });
};
ReqLimiter.reqWithCheck('myPort', fetchToImage, { id: 'myImgId' }).then((data) => {
    // console.log(data)
    // returns result to call fetchToImage
});

Documentation generated with doxdox.