New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

no-race

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

no-race

`no-race` is a simple library for JavaScript/TypeScript to queue promises in case of concurrency and race conditions.

latest
Source
npmnpm
Version
0.0.3
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

no-race

no-race is a simple library for JavaScript/TypeScript to queue promises in case of concurrency and race conditions.

EagerQueue

EagerQueue provides a best-effort queue, it queues and executes tasks in order.

import { EagerQueue } from 'no-race'
import { sleep } from 'bun'

results = []
promises = []

const eagerQueue = new EagerQueue()

for (let i = 0; i < 10; i++) {
    const done = eagerQueue.enqueue(async () => {
        await sleep(Math.random() * 100)
        results.push(i)
    })
    promises.push(done)
}

await Promise.all(promises)

// expected output: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
console.log(results)

LazyQueue

LazyQueue provides a queue that skips when it is busy; this is very helpful when each task is extremely resource-consuming.

import { LazyQueue } from 'no-race'
import { sleep } from 'bun'

results = []
promises = []

const lazyQueue = new LazyQueue()

for (let i = 0; i < 10; i++) {
    const done = lazyQueue.enqueue(async () => {
        await sleep(Math.random() * 100)
        results.push(i)
    })
    promises.push(done)
}

await Promise.all(promises)

// expected output: [0], maybe one or two more due to the indeterminism of `random` 
console.log(results)

FAQs

Package last updated on 21 Mar 2024

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