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

dreadlocks

v3.0.0

Published

Dread-free locks that drive consistency.

Readme

dreadlocks

Dread-free locks that drive consistency.

Summary

Dreadlocks allows you to create deadlocks on a set of keys. There is no limitation as to what key can be, it could be an Object, an Array, a String, or anything that can be a key in Map.

  • Create and use keys to identify objects:
    • const key1 = {};
  • Create key sets for keys involved in each task:
    • const keySet = [key1, key2, key3]
  • Lock these key sets
    • Dread.lock(keySet).then(task)
  • Release these key sets once you're done.
    • Dread.release(keySet)

Perks

  • Respects FIFO (first-in-first-out) flow:
    • Iterates on queue item 0 to n then back to 0.
    • Reverts index to 0 on each performed lock.
    • Reverts index to 0 on each performed release.
  • Uses Map so you can use anything as a key.
    • Although of course, use of strings are the most encouraged.
  • Uses setInterval for periodic checks and processing of queue.
    • new Dreadlock(interval) accepts custom interval in ms, 4 by default; 1000/4 = 250 checks/s

Use Cases:

  • Database consistency & transactions.
  • Ensuring order in execution of tasks that wish to modify possibly similar objects or entities.

API

Constructor

new Dreadlocks({ defaultLockTimeout = Infinity })

Construct an instance of Dreadlock. You can also set a default timeout to wait for a lock.

Methods

#lock(keyset[], { lockTimeout = this.defaultLockTimeout } = {})

  • keyset array of keys to lock
  • lockTimeout timeout in ms for the lock to be obtained

Return a Promise which will resolve when the lock is obtained, or reject when the timeout is reached.

#release(keyset[])

  • keyset array of keys to release

Properties

#size

Current size of instance Map


Usage:

Install

npm install dreadlocks --save
yarn add dreadlocks
const Dreadlock = require('dreadlocks');

Create instance

const Dread = new Dreadlock();

Lock your keys anywhere in your code:

const keySet1 = ['key1', 'key2', 'key3'];
Dread.lock(keySet1)
  .then(() => {
    console.log('Working with keySet1.');
    // Use your keySet1 keys here
    console.log('Done with keySet1.');
    return Dread.release(keySet1);
  })
  .then(() => {
    console.log('keySet1 released.');
  });
const keySet2 = ['key1', 'key4', 'key5'];
Dread.lock(keySet2)
  .then(() => {
    console.log('Working with keySet2.');
    // Use your keySet2 keys here
    console.log('Done with keySet2.');
    return Dread.release(keySet2);
  })
  .then(() => {
    console.log('keySet2 released.');
  });

See the magic:

Working with keySet1.
Done with keySet1.
keySet1 released.
Working with keySet2.
Done with keySet2.
keySet2 released.

LICENSE

C 0