npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@meislzhua/promise-pool

v1.1.0

Published

Easy Promise thread pool tool

Readme

promise-pool

简体中文版说明

What do you do when you have a set of async tasks to deal with?

//use for? If async tasks take a long time, they are too inefficient
for(let task of tasks){
    await task();
}

or

//use Promise.all,all tasks are executed together?
//it may be a good idea,but when you have a task that takes up a lot of resources, all the tasks are executed at the same time, there may be some surprises
await Promise.all(tasks.map(task => task()))

now,You can limit the amount of Promise thread count through 'promise-pool'!

let pool = new Thread({threadCount:10});

for(let task of tasks){
    pool.run(()=>task())
}
await pool.finish();

//or

await Promise.all(tasks.map(task => {
    return  pool.run(()=>task())
}))

Install

yarn add @meislzhua/promise-pool

or

npm i @meislzhua/promise-pool --save

Usage

//Any of the import ways can be used
//import Thread from "@meislzhua/promise-pool"
//import {Thread}from "@meislzhua/promise-pool"

let {Thread} = require("@meislzhua/promise-pool");

(async ()=>{
    //Create a new thread pool that can only run five tasks at once
    let pool = new Thread({threadCount:5});
    

    //If you have batch tasks to deal with
    for(let i = 0; i < 10; i++){
        pool.run(async ()=>{
            //your task ,doSomeThing
            
            //delay 1 second
            await new Promise(resolve => setTimeout(resolve,1000))
            console.log("finish!");
            return Math.random()
        }).then(data=>{
            //data is your task return
            console.log(data) //Math.random()

        }).catch(error =>{
            //If your task is likely to report errors, you need to catch
        })
    }   

    //Gets the number of remaining tasks(This includes what is being executed and what is waiting to be executed)
    console.log(pool.count());
    
    //You can call the Finish function when you need to wait for all tasks to complete
    await pool.finish()
})()

Other

This project is written with 'Typescript', and the compiled JS version is' esnext '

If you have a compatible version, go to the 'node_modules/@meislzhua/promise-pool' directory and modify 'tsconifg.json' and recompile