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

fn.locky

v1.0.0

Published

Lock utils for asynchronous function to avoid concurrent calls

Readme

fn.locky

Lock utils for asynchronous function to avoid concurrent calls.

npm npm Codecov npm bundle size GitHub Workflow Status (with event)

  • ✨ Written in TypeScript
  • ✨ Lock/unlock automatically
  • 100% Tests coverage
  • ✨ Support Tree-Shaking
  • 732 B + 5.4 KB gzip (subpath import)

Install

npm i fn.locky -S

Usage

This package contains two useful tools:

  • AsyncLock: A semantic encapsulation based on Promise, controls the function execution flow manually.
  • lockify: A higher-order function, for adding lock protection to the functions, fully automatic locking and unlocking

Basic usage

use AsyncLock in functions

import { Lock, AsyncLock } from "fn.locky";
// create
const lock = Lock.createAsyncLock();
// or
const lock = new AsyncLock();

// lock
lock.lock();

// inside the function
// judge status to wait or continue
if (lock.locked) {
  // waiting util unlock
  await lock.pending;
}
console.log('done');

// outside the function
// unlock
lock.unlock(); // log 'done'

Advanced usage ✨✨

lockify

Convert a lockable function to a lockified function, manage locking and unlocking automatically.

Yep, we do distinguish between different function parameters, see these test cases for details

import { lockify } from "fn.locky";

let count = 0;
const asyncFn = (param1, param2) =>
  new Promise((resolve) => {
    // mock request
    setTimeout(() => {
      // do something with param1 and param2
      resolve({ success: true, count: count++ }); // auto unlock the (inner) lock
    }, 1000);
  });

const lockified = lockify(asyncFn);

// concurrent calls
const result_1 = lockified();
const result_2 = lockified();
const result_3 = lockified();

// after first call resolves:
// count: 1
// result_1, result_2, result_3: { success: true, count: 1 }

NOTICE:

  • We assume that the lockable function should be a pure function( fn(x) always return y, what means the function has no side effects ), so the other waiting calls would return the same result immediately when unlocking instead of re-calling the original lockable function.
  • lockify not support lockable functions that use arguments object inside or something like rest parameter. Cause we cannot tell whether the function has parmaters list or not. In this case, you should pass another parameter useParams manually

subpath-import

You can only import Lock class, it only costs 732 B !

Additions: You may set moduleResolution field to node16/nodenext in your tsconfig.json, see here.

import { Lock, AsyncLock } from "fn.locky/lock";
import { lockify } from "fn.locky/lockify";