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 🙏

© 2024 – Pkg Stats / Ryan Hefner

dreadlocks2

v2.0.1

Published

Dread-free promise-based locks, 2 because it's a rewrite.

Downloads

7

Readme

dreadlocks2

Dread-free locks that drive consistency.

Summary

  • Create and use keys to identify objects:
    • let key1 = hash(whatever)
    • let key2 = {whatever: 'whatever'}
    • let key3 = Symbol('whatever')
  • 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 on every release.
  • Uses Map so you can use anything as a key.
    • Map has higher limits than Object.

Use Cases:

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

Changelog

  • v2.x
    • Removed setInterval, smarter locking mechanism.
  • v1.x
    • Uses setInterval, has immediate-locking mechanism.

class Dreadlock

  • constructor ()
  • method lock (items)
    • items array of keys to lock
    • RETURNS Promise, resolves on lock success
  • method release (items)
    • items array of keys to release
    • RETURNS Promise, resolves on release success
  • property size
    • RETURNS current size of instance Map
  • property length
    • RETURNS current size of instance Array queue

Usage:

  • Install:
npm install dreadlocks2 --save
yarn add dreadlocks2
const Dreadlock = require('dreadlocks2');
  • 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

Attribution 4.0 International (CC BY 4.0)

  • https://creativecommons.org/licenses/by/4.0/
  • https://creativecommons.org/licenses/by/4.0/legalcode.txt

cc by