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 🙏

© 2026 – Pkg Stats / Ryan Hefner

best-queue

v3.0.7

Published

Queue in runtime base promise

Downloads

89

Readme

license downloads size issues npm

English|简体中文

Introduction

best-queue let you control tasks in a queue.

It's easy to execute task one by one with interval time in queue like this:

Queue -> task -> wait(interval) -> task -> wait(interval) -> task -> finish

How about adding async task in queue:

Queue -> Promise.resolve(task) -> wait(interval) -> Promise.resolve(task) -> wait(interval) -> Promise.resolve(task) -> finish

What if we want to execute two tasks at the same time to support concurrency in queue:

Queue -> Promise.all([Promise.resolve(task), Promise.resolve(task)]) -> wait(interval) -> Promise.all([Promise.resolve(task), Promise.resolve(task)]) -> wait(interval) -> Promise.all([Promise.resolve(task), Promise.resolve(task)]) -> finish

But if one async task takes too much time because of network reason, the batch of task need to wait until the slow task resolve, we can do something make queue more efficient in theory.

That's best-queue do. See image below.

Install

type in the command line to install with:

npm i best-queue

Usage

Import as an ES Module:

import { createQueue } from "best-queue";

Require in Node:

const { createQueue } = require("best-queue");

Use Script source(Exposed BQueue as global var):

<script src="https://cdn.jsdelivr.net/npm/best-queue"></script>
<script src="https://unpkg.com/best-queue"></script>

API

| Attribute/Method | Description | Type | Default | | :------------------------------- | -------------------------------------------------------------- | :--------------------------------------------------- | -------------------------------------------------------- | | createQueue | create a queue | (tasks: unkonwn[], options: Options) => Promise | | | options | create a queue by options | Object | {max: 1, interval: 0,recordError: false} | | options.max | max concurrence task at the same time, default and min to 1 | Number | 1 | | options.interval | the interval time between tow tasks(milliscond), default to 0 | Number | 0 | | options.recordError | record error task instead of reject queue when task gone error | Boolean | false | | pause() | pause the queue, queue stop to execute task | Function(): void | | resume() | rerun the queue | Function(): void | | subscribe(listener: Listener) | listener fired a task done | Function(({taskStatus: 'success' | 'error', data: unknown, taskIndex: number, progress: number}) => void): () => void |

Example

import { createQueue } from "best-queue";

// simulate async task
function asyncTask() {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve(1);
    }, 1000);
  });
}

const asyncTasks = [asyncTask, asyncTask];

/**
 * createQueue returns enhanced promise
 */
const queue = createQueue(asyncTasks, {
  max: 1,
  interval: 1 * 1000,
  recordError: false,
});

queue.then((result) => {
  console.log(result);
});

const unsubscribe = queue.subscribe(({ taskIndex }) => {
  // queue will be paused after first task
  taskIndex === 0 && queue.pause();
});

setTimeout(() => {
  // queue paused after first task done, it will rerun the queue
  queue.resume();
}, 1500);

Lisence

Copyright (c) 2020 Jacano Licensed under the MIT license.