★ wanayoo — archive 1999 https://github.com/joway/node-routineNouvelle recherche | Portail wanayoo
Skip to content
A library to implement Goroutine-Like API with worker_threads.
TypeScript JavaScript
Branch: master
Clone or download
Latest commit 95c554d Nov 7, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci release: 0.2.1 (#5) Nov 7, 2019
bench add benchmakr Sep 7, 2019
docs update doc Nov 7, 2019
public [ImgBot] Optimize images (#3) Sep 7, 2019
src release: 0.2.1 (#5) Nov 7, 2019
tests feat: add shutdown Aug 27, 2019
.gitignore feat: add shutdown Aug 27, 2019
.npmignore feat: add shutdown Aug 27, 2019
CNAME doc: add CNAME Aug 27, 2019
README.md add benchmakr Sep 7, 2019
example.js add benchmark Aug 27, 2019
jest.config.js add benchmark Aug 27, 2019
jest.setup.js add benchmark Aug 27, 2019
logo.sketch add benchmakr Sep 7, 2019
package-lock.json release: 0.2.1 (#5) Nov 7, 2019
package.json release: 0.2.1 (#5) Nov 7, 2019
tsconfig.json add benchmark Aug 27, 2019
tslint.json feat: add shutdown Aug 27, 2019
typedoc.json doc: add public docs Aug 27, 2019

README.md

node-routine

npm npm

node-routine is a library to implement Goroutine-Like API with worker_threads.

Compared to using the worker threads low level API directly, node-routine can make your codes more elegantly, like:

await go(() => (Math.random()))

Documentation

Documentation

Architecture

Requirement

  • Nodejs >= 11.7
  • Nodejs >= 10.5 with --experimental-worker flag

Install

npm install -S node-routine

Quick Example

const { go, init, shutdown } = require('node-routine')

// init a worker threads pool
init({
  maxWorkerThreads: 2,
})

async function calc() {
  // every routine will be executed in worker threads pool
  const count = 10000
  const num = await go(() => {
    let total = 0
    for (let i = 0; i < count; ++i) {
      total += i
    }
    return total
  }, { count })

  return num
}

calc().then((total) => {
  console.log('Got', total)
  shutdown()
})

Benchmark

Benchmark Code

Env: Macbook Pro, 13-inch, 2018, 2.3 GHz Intel Core i5

Commend: npm run bench

  ✓ CPU intensive task using microjob (14ms)
  ✓ CPU intensive task using node-routine (4ms)
  ✓ IO intensive task using microjob (20163ms)
  ✓ IO intensive task using node-routine (5224ms)
You can’t perform that action at this time.