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

rately

v1.0.0

Published

A package for executing arbitrary functions in a rate limit compliant fashion

Downloads

5

Readme

rately

A lightweight (7kb!) package for executing arbitrary functions in a rate limit compliant fashion. Intended for both front and back end JS environments.

Installation

You can grab the latest version from NPM:

npm install rately

Usage

rately exports two types of executors, one that executes work serially, and another that does so concurrently.

import { SerialRatelyExecutor, RatelyExecutor } from 'rately';

/* this will never execute more than one job at a time */
const serialExecutor = new SerialRatelyExecutor({ ...options });

/* this can run the configured max number of jobs per interval at a time */
const concurrentExecutor = new RatelyExecutor({ ...options });

or in Node environments

const Rately = require('rately');

const serialExecutor = new Rately.SerialRatelyExecutor({ ...options });
const concurrentExecutor = new Rately.RatelyExecutor({ ...options });

Enqueueing jobs

Work can be supplied to executors as objects (jobs) in the form:

{
  workFn: () => {},
  cbFn: () => {}
}

cbFn is an optional callback function that will be called with the result/return value of workFn. You can also return Promise objects in workFn:

{
  workFn: () => Promise.resolve('work complete!')
}

Then, you can add work to the queue by calling add():

/* RatelyExecutor show here, but both types have the same interface */

const executor = new RatelyExecutor({ ...options });
executor.add({ workFn: () => {} });

/* you can enqueue multiple jobs by specifying them as additional arguments */
executor.add({ workFn: () => {} }, { workFn: () => {} }, ...);

Note that calling add() will immediately start running enqueued jobs if it is not already doing so.

Options

You are able to customize the behavior of the executors by supplying an options object to the constructor. The available options are:

{
  maxOperationsPerInterval?: number,  // defaults to 10
  rateLimitIntervalMs?: number,       // defaults to 10_000
  bufferMs?: number                   // defaults to 100
}
  • maxOperationsPerInterval - The maximum number of jobs to run per rate limit interval
  • rateLimitIntervalMs - Time in milliseconds that each rate limit interval lasts
  • bufferMs - This is a safety buffer of additional time (in milliseconds) that the executor will wait until deciding when an interval ends. Given the implementation of how executors keep track of time (via setInterval), it is not guaranteed that work will be executed exactly when it should. For example, with the default values, rately will consider one interval 10,000 + 100 milliseconds long, and pick up more jobs when that time has elapsed.

License

MIT