A simple locking mechanism for serializing access to a resource using promises. Version 1.0.1 is the latest stable release. This package provides a Locker class that manages a queue of promise-returning functions, supporting both exclusive and non-exclusive locks. Exclusive locks block all other operations until they complete, while non-exclusive locks run concurrently. This is useful for controlling access to shared resources without full mutex complexity. It has zero runtime dependencies and is designed for Node.js environments (>=0.10.0), with no browser support. Compared to alternatives like async-lock, lock-queue offers a minimal API focused on queue-based serialization with concurrency support for non-exclusive tasks.
npm install lock-queueNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates creating a Locker, adding non-exclusive tasks with .run(), and an exclusive task with .lock(). Tasks 1 and 2 run concurrently, exclusive 3 waits for them, then task 4 waits for 3.
Ensure all functions passed to .lock() and .run() return a promise (or use async functions).
Use regular functions (not arrow functions) if you need a custom 'this' context.
Implement your own timeout/cancellation logic within the promise-returning function.
Use require('lock-queue') instead of import. Alternatively, use dynamic import() which works in ESM: const { default: Locker } = await import('lock-queue');Ensure you have installed version 1.0.1: npm install lock-queue@1.0.1. Then require: const Locker = require('lock-queue'); const locker = new Locker();Attach a .catch() handler to the promise returned by .run() or .lock(): const promise = locker.run(fn, ctx); promise.catch(err => console.error(err));
No dependency data recorded yet.