Socket
Book a DemoInstallSign in
Socket

lockify

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lockify

If your async function shouldn't run concurrently, lockify it!

2.0.0
latest
Source
npmnpm
Version published
Weekly downloads
1
-75%
Maintainers
1
Weekly downloads
 
Created
Source

Lockify

Leverage promises to ensure a function doesn't execute concurrently

Most asynchronous functions are fine to run concurrently with themselves. But when they're not—lockify them.

Lockify takes an async function (or any function that returns a promise), and lets you limit concurrency. By default the maximum concurrency is 1.

Let's say we're getting dog descriptions from an API:

const headers = { Authorization: 'Bearer abc123xyz890' }
function fetchDog(name) {
  const url = `http://example.com/dog/${name}`
  return fetch(url, { headers }).then(res => res.json())
}

const allDogs = Promise.all(
  ['Fido', 'Princess', 'Fluffy'].map(fetchDog)
)

Unfortunately this API doesn't allow your key to fetch more than one dog at a time. Lockify can help with that:

const headers = { Authorization: 'Bearer abc123xyz890' }
function fetchDog(name) {
  const url = `http://example.com/dog/${name}`
  return fetch(url, { headers }).then(res => res.json())
}

const politeFetchDog = lockify(fetchDog)

const allDogs = Promise.all(
  ['Fido', 'Princess', 'Fluffy'].map(politeFetchDog)
)

Or, if you've paid more for the "fetch two dogs at a time" plan with the dog description service:

const politeFetchDog = lockify(fetchDog, 2)

Keywords

async

FAQs

Package last updated on 09 Jul 2025

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.