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

@masx200/universal-thread-pool

v1.0.6

Published

Universal thread pool 通用线程池

Downloads

106

Readme

universal-thread-pool

Universal thread pool 通用线程池

适用于 CPU 密集型的任务的 通用线程池

由于JavaScript有异步方式处理IO密集型任务,所以不应该在线程池中使用IO密集型任务.

可以与 comlink 配合使用实现,浏览器或者 denoweb worker 线程池,或者 nodejsworker_threads 线程池

https://www.npmjs.com/package/comlink

导入模块

deno

指定版本号

import {} from "https://deno.land/x/[email protected]/mod.ts";
import {} from "https://cdn.jsdelivr.net/gh/masx200/[email protected]/mod.ts";

node

import {} from "@masx200/universal-thread-pool";

createThreadPool:创建线程池,

接受必选参数create:创建抽象线程的函数

接受必选参数terminate:结束抽象线程的函数

接受可选参数maxThreads:线程池中最多的线程数,默认为 cpu 个数

接受可选参数minThreads:线程池中最少的线程数,默认为 1.

ThreadPool线程池接口

destroy:销毁线程池中所有线程

run:在线程池中使用一个线程运行指定的callback回调函数,并返回结果,可选第二个参数signal可以使用AbortSignal来提前终止线程的运行.

threads:可以查看所有的线程.

onPendingSizeChange:添加监听器callback,当正在运行的任务数改变时,监听器被调用,返回一个停止监听的函数。

onQueueSizeChange:添加监听器callback,当正在排队的任务数改变时,监听器被调用,返回一个停止监听的函数。

查看 web worker 例子

https://github.com/masx200/universal-thread-pool/tree/main/test/test.ts