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

@eluneevermore/single-flight

v1.0.1

Published

Deduplicate concurrent async work with local and distributed coordination channels.

Readme

@eluneevermore/single-flight

Deduplicate concurrent function calls. When multiple callers request the same work simultaneously, only one execution runs and all callers share the result.

Works across processes and machines via pluggable Channel implementations (Redis, IPC, Kafka, etc.).

Installation

pnpm add @eluneevermore/single-flight

If you want the Redis channel:

pnpm add @eluneevermore/single-flight ioredis

Usage

Direct

import { SingleFlightGroup } from "@eluneevermore/single-flight"

const sf = new SingleFlightGroup()

// Both calls share the same execution
const [a, b] = await Promise.all([
  sf.execute("user:123", () => fetchUser(123)),
  sf.execute("user:123", () => fetchUser(123)),
])
// fetchUser called once, a === b

Wrapper function

import { withSingleFlight } from "@eluneevermore/single-flight"

const getUser = withSingleFlight(
  (id: number) => fetchUser(id),
  (id) => `user:${id}`,
)

// Concurrent calls with the same key share one execution
await Promise.all([getUser(1), getUser(1), getUser(2)])

Decorator

import { SingleFlight } from "@eluneevermore/single-flight"

class UserService {
  @SingleFlight((id: number) => `user:${id}`)
  async getUser(id: number) {
    return await db.query("SELECT * FROM users WHERE id = ?", [id])
  }
}

Distributed usage

Without a channel, deduplication is local to the process. To deduplicate across processes or machines, provide a Channel implementation:

import { SingleFlightGroup } from "@eluneevermore/single-flight"
import { RedisChannel } from "@eluneevermore/single-flight/channels/redis"

const sf = new SingleFlightGroup({
  channel: new RedisChannel(redisClient),
  timeout: 30_000,
})

Timeout

When using a channel, set timeout (in milliseconds) to prevent waiters from hanging forever if the executor crashes:

const sf = new SingleFlightGroup({
  channel: new RedisChannel(redis),
  timeout: 30_000,
})

Without a timeout, if the executor process crashes after acquiring the lock but before publishing the result, all waiters on other processes will hang indefinitely.

The timeout only affects the waiter path (callers that do not acquire the lock). It does not limit the executor. Use your own timeout on fn() for that.

On timeout, waiters reject with SingleFlightTimeoutError and automatically clean up their channel subscription.

Channel interface

A channel coordinates lock acquisition and result broadcasting across processes. The protocol is subscribe -> acquire -> release:

import type { Channel, Result, Subscription } from "@eluneevermore/single-flight"

class MyChannel implements Channel {
  async subscribe(key: string): Promise<Subscription> { /* ... */ }
  async acquire(key: string): Promise<boolean> { /* ... */ }
  async release(key: string, result: Result): Promise<void> { /* ... */ }
  async dispose(): Promise<void> { /* ... */ }
}

subscribe must be called before acquire to avoid a race where the result is published between the lock check and subscription setup. SingleFlightGroup handles this ordering automatically.

Built-in channels

| Channel | Import | Scope | |---------|--------|-------| | LocalChannel | @eluneevermore/single-flight/channels/local | Single process (testing) | | RedisChannel | @eluneevermore/single-flight/channels/redis | Distributed (multi-process/machine) |

API

SingleFlightGroup

| Method | Description | |--------|-------------| | execute<T>(key, fn) | Run fn under deduplication for key | | forget(key) | Remove key from in-flight map, allowing re-execution | | dispose() | Cleanup the channel |

Options:

| Option | Type | Description | |--------|------|-------------| | channel | Channel | Channel for distributed coordination | | timeout | number | Waiter timeout in ms. Rejects with SingleFlightTimeoutError on expiry |

@SingleFlight(keyFn, options?)

Method decorator that deduplicates calls based on the key returned by keyFn.

withSingleFlight(fn, keyFn, options?)

Wraps a function with deduplication. Returns a new function with the same signature.

Release

This package is published from GitHub Actions.

  1. Update package.json with the next semver version.
  2. Commit the change and push it.
  3. Create and push a matching tag such as v0.1.3.
  4. The publish workflow verifies the tag matches package.json, then runs npm publish --provenance.