
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
make-concurrent
Advanced tools
make-concurrent is a function which create function with limited parallel execution of passed function according with passed concurrency option (1 by default).
It's not replacement of lodash.debounce / lodash.throttle. Created function called immediately if current executed functions not excess concurrency option, otherwise call will be blocked until previous called functions not finished.
make-concurrent functions does not make any sense for synchronous functions, because JS can not execute more than 1 same synchronous function at one time, it's can be useful only for async functions.
Callbacks are not supported, async functions with us from Node v7.6.0 (2017-02-22), please use it.
npm:
npm install https://github.com/fanatid/make-concurrent
yarn:
yarn add https://github.com/fanatid/make-concurrent
By default npm / yarn will install code from master branch. If you want specified version, just add some branch name / commit hash / tag and the end of URL. See Yarn add or npm install for details about installing package from git repo.
Anywhere where you need limited access to some resource.
When we call function created by make-concurrent counter of called functions increased by 1, then increased counter compared with concurrency option, if counter is greater than concurrency then we create Promise, push resolve function to queue (FIFO) and wait while this Promise will be resolved, before call original function. When execution of original function will be finished we decrease counter on 1 and check queue, if queue length is not zero we take first item and call it, which resolve Promise and original function will be called again.
All code is less than 50 lines, just check it. This will take 2 minutes, but will give better understanding how make-concurrent works and how can be used effectively.
Assume you need make requests to some API, but this API have limit of simultaneous requests by API key.
const makeConcurrent = require('make-concurrent')
const fetch = require('node-fetch')
async function request (user) {
return fetch(`https://example.org/getinfo?user=${user}&apikey=${process.env.API_KEY}`)
}
module.exports = makeConcurrent(request, { concurrency: 3 })
Now only 3 request function will work at one moment.
Sometimes we have state and need work with it from async functions which can be executed at one time.
const makeConcurrent = require('make-concurrent')
const state = {}
async function unsafeUpdate (user) {
const currentValue = state[user] === undefined ? 0 : state[user]
const newValue = await getNewValue(user, currentValue)
state[user] = newValue
}
const safeUpdate = makeConcurrent(unsafeChange)
// safeUpdate('alice')
While safeUpdate going to be safe function for working with state, it's good as general approach. But here state changed for specified user, so we can use the .byArguments() method:
const makeConcurrent = require('make-concurrent')
const state = {}
async function unsafeUpdate (user) {
const currentValue = state[user] === undefined ? 0 : state[user]
const newValue = await getNewValue(user, currentValue)
state[user] = newValue
}
const safeUpdate = makeConcurrent.byArguments(unsafeUpdate)
// safeUpdate('alice')
FAQs
Easy exclusive or shared access to resource
The npm package make-concurrent receives a total of 5,678 weekly downloads. As such, make-concurrent popularity was classified as popular.
We found that make-concurrent demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?

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.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.