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

thread-pool-ts

v1.0.3

Published

基于 worker_threads 的通用线程池任务执行器(支持并发控制、顺序输出、超时终止)

Downloads

16

Readme

🧵 ThreadPool - Node.js 多线程任务池

基于 worker_threads 封装的轻量级线程池,支持:

  • 多任务并发执行(限制最大并发)
  • 支持顺序回调(按任务 index 顺序)
  • 支持任务超时控制
  • 支持任务完成后的钩子函数(onComplete)
  • 任务结果收集(可选)

📦 安装

npm install thread-pool-ts
# or
pnpm add thread-pool-ts

⚠️ 仅支持 Node.js 12+,不支持浏览器环境。


✨ 快速使用

import { ThreadPool } from "thread-pool-ts";

const pool = new ThreadPool({
  workerPath: "./worker.js", // Worker 文件路径
  maxConcurrency: 4, // 最大并发数
  isSequential: true, // 是否按顺序执行 onResult
  timeout: 5000, // 每个任务超时时间(毫秒)
});

const tasks = ["任务1", "任务2", "任务3"];

pool.run<string, string>({
  tasks,
  onResult: (res, i) => {
    console.log(`第 ${i} 个结果:`, res);
  },
  onComplete: (allResults) => {
    console.log("所有任务完成:", allResults);
  },
});

npm version