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

webstorage-mutex

v0.1.1

Published

Fast mutual exclusion for safe cross tab Web Storage access

Downloads

5

Readme

webstorage-mutex 🔒

npm version

Fast mutual exclusion for safe cross tab Web Storage access

Installation

npm install webstorage-mutex
# yarn add webstorage-mutex

Example

import { mutex } from 'webstorage-mutex';

mutex(
  () => {
    let v = window.localStorage.getItem('test-item');
    if (!v) {
      v = '*';
    } else {
      v = v + '*';
    }
    window.localStorage.setItem('test-item', v);
    return v;
  },
  {
    lockPrefix: 'webstorage-mutex',
    repeatInterval: 50,
    repeatTimeout: 1000, // <- this should be the upper bound of your critical section
    delayTime: 50, // <- this is assumed to be long enough for any tab to complete localStorage getItem and setItem
  }
)
  .then((value) => {
    console.log(value);
  })
  .catch((reason) => {
    if (reason.message === 'mutex timeout') {
      // handle scenario where critical section executes too long
    }
  });

Reference

R. Alur and G. Taubenfeld, "Results about fast mutual exclusion"

Pseudocode: https://www.cs.rochester.edu/research/synchronization/pseudocode/fastlock.html#at

Code to be executed by process i. Variables Y and Z are initialized to free and 0, respectively. The delay at line 6 is assumed to be long enough for any process that has already read Y = free in line 3 to complete line 4, and any process that has already set Y in line 4 to complete line 5 and (if not delayed) line 11 (that is the time required to service 2 memory references by all other processors in the system).

  1:     start:
  2:        X := i
  3:        repeat until Y = free
  4:        Y := i
  5:        if X <> i
  6:           { delay }
  7:           if Y <> i
  8:              goto start
  9:           repeat until Z = 0
  10:       else
  11:          Z := 1
  12:    { critical section }
  13:       Z := 0
  14:       if Y = i
  15:          Y := free
  16:    { non-critical section }
  17:       goto start