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

muti-thread

v2.0.6

Published

A framework let node support multi threads

Downloads

26

Readme

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

A framework let node support multi threads

Getting Started

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

If we let fast-diff run in a thread, we should

1 npm install fast-diff

2 create export.js

'use strict';

const fastDiff = require('fast-diff');

(function($) {
  $.fastDiff = function(good, bad, position) {
    var r;
    if(arguments.length === 2) {
      r = fastDiff(good, bad);
    } else {
      r = fastDiff(good, bad, position);
    }
    return JSON.stringify(r);
  }
})(global);

3 create webpack.config.js

'use strict';

var webpack = require('webpack');
var path = require('path');

module.exports = {
  target: 'web',
  entry:  {
    app: './export.js',
  },
  output: {
    path: path.join(__dirname, 'out'),
    filename: 'export.js'
  },
  resolve: {
    extensions: ['.js', '.json'],
    modules: [
      'node_modules'
    ],
  },
  externals:{},
  module: {
    loaders: [
    ]
  }
};

4 webpack --config webpack.config.js

5 the output file can be used

'use strict'

const co = require('co')
const Thread = require('muti-thread').Thread
const randomstring = require('randomstring')
const path = require('path')

// create a new thread
var thread = new Thread(path.join(__dirname, 'test', 'out', 'export.js'))

co(function* () {
  for(;;) {
    var good = randomstring.generate(1000)
    var bad = randomstring.generate(1000)
    var r = yield thread.execute('fastDiff', new Buffer(good), new Buffer(bad))
  }
})

Platform Support

OS X, Windows and Linux

Node engine

>=4.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 2015 or newer
  Python 2.6 or 2.7

Once you have Node.js installed:

npm install -g node-gyp
npm install muti-thread

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。

A simple test report

License

Apache-2.0