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 🙏

© 2026 – Pkg Stats / Ryan Hefner

process-worker-executor

v2.0.5

Published

将多进程和多线程封装为统一的 Async/Await 调用方式, 简化 IPC 消息通信的复杂性

Readme

Process Worker Executor

通过将进程和线程的调度封装为普通方法的调用方式简化了异步调用的复杂性。

功能

  1. 使用 Async/Await 封装了 Nodejs 进程、线程调用
  2. 通过简单的异步方法屏蔽了 IPC 通信细节
  3. 使用代理的方式将同步方法代理为异步调用

注意

默认情况下代理的方法需要在方法本身的参数列表外的下一个明确指定使用异步

// math add 方法定义的时候有两个参数,那么代理以后第三个参数指定是否异步执行
function add(a, b) {
    return a + b
}
// 禁用异步执行
const sum = await math.add(1, 2)
// 禁用异步执行
const sum = await math.add(1, 2, false)

// 启用异步执行
const sum = await math.add(1, 2, true) // 明确指定启用异步

用法

任务运行于独立进程

需要异步执行的脚本, 普通脚本即可

math.js

async function add(x, y) {
    return x + y
}

async function sub(x, y, cb) {
    cb()
    return x - y
}

module.exports = {
    add,
    sub
}

调用方式

const { requireScript } = require('process-worker-executor')

const mathPath = join(__dirname, 'math.js')
const math = await requireScript(mathPath, 'Process', {
    ttl: 60 * 1000,
    metedata: {
        // 其他需要传递给 Math 中函数使用的附加参数
        // 在 math.js 中使用 this._metedata 访问元数据对象
        // ...
    }
})
// 异步包装器会为代理的方法额外添加一个参数指定是否使用异步执行
// 此功能主要是为了方便用户动态指定其是否异步执行
// 方法支持传递函数作为其参数

// 主线程执行
const sum = await math.add(1, 2)
// 子线程/进程执行
const sum = await math.add(1, 2, true)
// 包含函数类型的参数
const sum = await math.sub(
    1,
    2,
    () => {
        // 函数可作为直接参数传递
        // 注意: 对象作为参数的时候, 对象中包含的方法不会传递
        // 具体支持的参数类型请查看[参数类型]
        // 函数类型参数通过消息传递调用, 此函数在主线程调用, 形参来自于子线程/进程的传参
        console.log('函数作为参数传递')
    },
    true
)

参数类型

  1. 原始数据类型 Number, String, Boolean, null, 和 undefined
  2. 普通的 JavaScript 对象和数组
  3. Node 中的 Buffer 类型。
  4. ArrayBuffer 和 Typed Array
  5. Structured Cloneable types: 这指的是可以被结构化克隆的对象, 包括 Date、Map、Set 以及包含这些对象的数组和对象。
  6. Process 和 Worker 模式下支持的参数类型略有不同
  7. 具体参数请参考 process.send 和 worker.postMessage 方法参数