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

delayed-lock

v0.0.1

Published

A 'lock' that can be acquired only after 'x' ms after it is released.

Downloads

5

Readme

Delayed Lock Build Status

Provides a Lock object that can be acquired only after a pre-configured delay after it is released. The Lock object is created as follows:

var Lock = require('delayed_lock');
var lock = Lock.create();

The following APIs are available on the lock created above:

  1. acquire(callback) - Acquire the lock. The key is passed to the callback of this API.
  2. release(key) - Release the lock. The key got during the acquire call should be passed as the argument to this call. If the key does not match the key of the lock then this call will be a noop.

The lock can be in one of the following states:

  1. AVAILABLE A lock can be successfully acquired, only when it is in the AVAILABLE state.
  2. ACQUIRED Once a lock is acquired, the lock is placed in the ACQUIRED state.
  3. DELAYING When a lock is released, it is immediately put in the DELAYING state for DELAY milliseconds (configurable). After the delay it is put to AVAILABLE state.

Delaying before unlocking

By default delay after a lock is released and before it is made available is set 1s. This can be cofigured either at a global level by setting the DELAYED_LOCK_DELAY environment variable or on a per-lock basis by passing a config parameter to the create call while creating the lock.

var 5_sec_delayed_lock = Lock.create({delay: 5000})

Configuring Locks

Delayed Locks can be configured either at a global level (affects all locks) or on a per-lock basis.

Global configurations

Locks can be configured by setting the following environment variables before requiring the delayed_lock module for the first time.

  1. DELAYED_LOCK_DELAY - The amount of time that the lock should be held after it is released, before making it available again. Note that this is the minimum time and not an exact time. However, it can be expected that the delay time is reasonably close to this value.
  2. DELAYED_LOCK_TIMEOUT - If set, the lock is made available after this period of time after it is acquired or when explicitly releases by the acquirer, whichever is earlier.
  3. DELAYED_LOCK_MIN_WAIT_TIME_BETWEEN_RETRIES' - If an acquire` call is made when the lock is not in AVAILABLE state, locking is automatically retried after 500ms. This time can be changed by setting this variable.

Per-lock configuration

A lock can be configured by passing a (optional) configuration object to the create call. The following configuration parameters are available:

  1. delay - same effect as DELAYED_LOCK_DELAY
  2. timeout - same effect as DELAYED_LOCK_TIMEOUT
  3. waitTime - same effect as DELAYED_LOCK_MIN_WAIT_TIME_BETWEEN_RETRIES

Testing

$> make test

Release notes:

0.0.1 - Initial Release

Contributions

Pull requests are very welcome :)