Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

@dwbinns/parallel

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dwbinns/parallel

Execute async jobs with specified parallelism

latest
Source
npmnpm
Version
2.0.0
Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

Run tasks with limited parallelism

import parallel from "@dwbinns/parallel";
import { setTimeout } from "timers/promises";

function run(id) {
  return async () => {
    console.log("Start", id);
    await setTimeout(10, id);
    console.log("End", id);
    return id;
  };
}

const queue = parallel(2);

const results = await Promise.all([
  queue(run(1)),
  queue(run(2)),
  queue(run(3)),
  queue(run(4)),
]);

console.log(results);
Start 1
Start 2
End 1
Start 4
End 2
Start 3
End 4
End 3
[ 1, 2, 3, 4 ]

FAQs

Package last updated on 05 Mar 2022

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