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

dena

v2.1.0

Published

Async Javascript Scheduler

Downloads

22

Readme

Dena

A tiny async task scheduler for JavaScript/TypeScript. Queue async functions against a pool of limited resources — Dena ensures only as many tasks run concurrently as there are resources available.

Install

npm install dena

Quick Start

const Dena = require("dena");

// You have 3 tokens, but 5 downloads to make.
// Dena manages the queue so only 3 run at a time.

const tokens = ["token_a", "token_b", "token_c"];

const download = async (token, url) => {
  const res = await fetch(`${url}?token=${token}`);
  return res.json();
};

const scheduledDownload = Dena(tokens, download);

// Dena assigns a free token automatically — just pass the remaining args:
const result = await scheduledDownload("/api/users");

How It Works

  1. You provide a resource pool (an array of configs/tokens/connections — anything).
  2. You provide an async worker function whose first argument is a resource from the pool.
  3. Dena returns a new function with the same signature minus the first argument. When you call it, Dena waits for a free resource, injects it, and runs your worker.
Dena(pool, worker) → scheduledWorker
  • If a resource is free, the task runs immediately.
  • If all resources are busy, the task is queued and runs as soon as one frees up.
  • Each call returns a Promise that resolves with the worker's return value.

Example

const Dena = require("dena");

const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));

const download = async (token, path, ms) => {
  console.log(`[ ] downloading ${path} (token=${token})`);
  await delay(ms);
  console.log(`[x] finished   ${path} (token=${token})`);
};

const tokens = ["t1", "t2", "t3"];
const scheduledDownload = Dena(tokens, download);

scheduledDownload("/one", 1000);
scheduledDownload("/two", 500);
scheduledDownload("/three", 2000);
scheduledDownload("/four", 500); // queued — waits for a free token
scheduledDownload("/five", 100); // queued

/*
  [ ] downloading /one   (token=t1)
  [ ] downloading /two   (token=t2)
  [ ] downloading /three (token=t3)
  [x] finished   /two   (token=t2)
  [ ] downloading /four  (token=t2)
  [x] finished   /one   (token=t1)
  [ ] downloading /five  (token=t1)
  [x] finished   /four  (token=t2)
  [x] finished   /five  (token=t1)
  [x] finished   /three (token=t3)
*/

API

Dena<TConfig, TArgs, TResult>(
  pool: TConfig[],
  worker: (config: TConfig, ...args: TArgs) => Promise<TResult>
): (...args: TArgs) => Promise<TResult>

| Parameter | Description | |-----------|-------------| | pool | Array of resources. Each element is passed as the first argument to worker when a task is dispatched. The pool size determines the concurrency limit. | | worker | Async function to schedule. Its first parameter receives a resource from pool; the rest are the arguments you pass to the returned function. |

Returns a function with the same signature as worker minus the first parameter. Each call returns a Promise that resolves with the worker's return value.

TypeScript

Full type definitions are included with the package — no extra @types install needed.

License

MIT