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 🙏

© 2025 – Pkg Stats / Ryan Hefner

typed-scheduler

v0.3.1

Published

A Scheduler written in TypeScript for concurrency-limiting and rate-limiting

Readme

typed-scheduler

A Scheduler written in TypeScript for concurrency-limiting and rate-limiting

Docs | GitHub | npm | Yarn

version npm bundle size devDependencies issues node support code style license

Table of Contents

Installing

npm

$ npm i --save typed-scheduler

Yarn

$ yarn add typed-scheduler

Importing

typed-scheduler is pre-bundled using the UMD pattern to support the following module formats.

ES Module

import Scheduler from 'typed-scheduler'

CommonJS

const Scheduler = require('typed-scheduler')

Browser Global

<script src="https://unpkg.com/typed-scheduler"></script>

AMD

define(['typed-scheduler'], function (Scheduler) {

})

Usage

Example

// rate limit to 2 messages every second
// defaults to 3 priorities
const scheduler = new Scheduler({ concurrency: 2, rate: 1000 })

// queue 120 messages synchronously
// scheduler will throttle to 2 messages per second
for (let i = 1; i <= 120; i++) {
  // schedule with normal priority
  scheduler.scheduleNormal(console.log, `message ${i}`)
}

priority

The second argument of schedule() is used to set the priority class of the scheduled function. The scheduler will handle scheduled functions in FIFO order within each priority class, and higher priorities will always be handled before lower priorities. A lower value means a higher priority.

ready() and idle()

The output of this program demonstrates when each of these methods resolves.

import Scheduler from 'typed-scheduler'

function print (...args) {
  console.log(`${(Date.now() / 1000).toFixed(3)}s`, ...args)
}

const scheduler = new Scheduler({ concurrency: 1, rate: 1000, priorities: 3 })

for (let i = 0; i < 3; i++) {
  for (let j = 0; j < 3; j++) {
    // interleave priority classes
    scheduler.schedule(
      () => print('task', i * 3 + j),
      j
    )
  }

  scheduler.ready(i).then(
    () => print(`priority ${i} ready`)
  )
}

scheduler.idle().then(
  () => print('scheduler idle')
)

Output

0.079s task 0
1.103s task 3
2.109s task 6
2.109s priority 0 ready
3.113s task 1
4.119s task 4
5.119s task 7
5.119s priority 1 ready
6.123s task 2
7.123s task 5
8.129s task 8
8.129s priority 2 ready
9.135s scheduler idle

concurrency and rate

Note that the following schedulers do not behave identically.

// 2 tasks every second
new Scheduler({ concurrency: 2, rate: 1000 })
// 1 task every half second
new Scheduler({ concurrency: 1, rate: 500 })

Using the options { concurrency: 2, rate: 1000 }, the scheduler will execute two tasks without delay, then wait a full second after either completes before executing another task.

Using { concurrency: 1, rate: 500 } will only execute one task at a time, then wait for half a second after it completes before executing another task.

API

The complete reference API is available on GitHub Pages.

License

Copyright © 2019 Patrick Roberts

MIT License