Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

localstorage-lock

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

localstorage-lock

Generic localstorage lock implementation

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.8K
increased by3.21%
Maintainers
1
Weekly downloads
 
Created
Source

localstorage-lock

Generic localstorage lock implementation

API

runWithLock

Run a specified code block with a localstorage lock

runWithLock(<localstorage key>, <fn to run>, <options>);

Options:

{
  timeout: 1000, // Time release the lock if function fails or takes too long
  lockWriteTime: 50, // Expected time to write to localstorage (unlikely to change)
  checkTime: 10, // How often to recheck the lock, if don't have the lock
  retry: true // Retry getting the lock, if not acquired
}

####Example Use


// Make sure only one browser window retrieves a localstorage key and does console.log
runWithLock('lock.some-key', () => {
  
  const someKey = localStorage.getItem('some-key');
  console.log(someKey)
  localStorage.removeItem('some-key')
}, { timeout: 500 });

tryRunWithLock

Wrapper function for tryWithLock with option retry: false

FAQs

Package last updated on 16 Feb 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc