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 🙏

© 2024 – Pkg Stats / Ryan Hefner

worker-thread2

v3.0.8

Published

A framework let node support multi threads

Downloads

3

Readme

-----------------------------✈--------------------------
   |-------------------------✈--------------------------
   |-------------------------✈--------------------------
   |-------------------------✈--------------------------

A framework let node support multi threads

Node Version Required

node >= 14.0.0

Dependencies

bluebird

Getting Started

This section contains guides for understanding and mastering features that this module offers.

you can run the file of main.js in sample folder.

jia@youjia MINGW64 /c/worker-thread2/sample
$ node main.js
thread is running
thread task number is 8
null apple+apple+
null {3C3EE61D-1B2E-4167-AA04-90E8510AD3DA}
null {3C3EE61D-1B2E-4167-AA04-90E8510AD3DA}
null {3C3EE61D-1B2E-4167-AA04-90E8510AD3DA}
null {3C3EE61D-1B2E-4167-AA04-90E8510AD3DA}
null {3C3EE61D-1B2E-4167-AA04-90E8510AD3DA}
null {3C3EE61D-1B2E-4167-AA04-90E8510AD3DA}
null {3C3EE61D-1B2E-4167-AA04-90E8510AD3DA}

Platform Support

OS X, Windows and Linux

Node engine

>=14.0.0

Cpu architectures

Not support arm , mips

Installation

Unix

  GCC 4.9.4 or newer
  Clang 3.4.2 or newer
  Python 2.6 or 2.7

Windows

  Building native add-ons: Visual Studio 2013 or Visual C++ Build Tools 2019 or newer
  Python 2.6 or 2.7

Once you have Node.js installed:

npm install -g node-gyp
npm install worker-thread2

OS X

xcodebuild

Having installation troubles? Check out Supported toolchains

APIs

close 通知线程对象管理的线程退出,即从线程的消息循环中退出,结束线程的运行。线程对象以后不再使用,应该调用这个函数,及时的释放系统资源。如果没有调用这个函数,而线程对象满足 V8 垃圾回收的条件被回收的时候,会自动释放底层资源。因此,这个函数的调用不是必须的。但我们建议,由于线程是系统资源,如果确定不再使用,应该手动调用 close 及时释放底层资源。

isRunning 判断这个线程对象是否存在可用线程。线程对象创建成功后,内部的线程已经就绪,调用这个函数返回 true。close 函数调用之后,isRunning 返回 false。

numOfTasks 交给线程对象执行的任务队列中的个数。即排队中的,还没来得及执行的任务个数。程序中可以创建多个线程对象,可以用这个函数做负载均衡,将任务交给 numOfTasks 个数最小的线程对象。

execute 让线程对象执行一个函数,每个函数就是一个任务,线程对象内部有一个消息队列,抛给线程对象执行的任务以队列的方式按序执行。这样的函数,execute 支持向它传递 [0, 8] 个参数,参数类型为 Buffer,如果是字符串,则自动转为 Buffer。

License

Apache-2.0

说明

我的这个解决方案是2017年做好的。比node原生模块worker_threads早。node 8, 10 的用户使用muti-thread,功能一样。个人感觉,这个实现方案用起来更简单,更好理解。