Update README.MD
[poolifier.git] / README.MD
... / ...
CommitLineData
1# Node Pool :arrow_double_up: :on:
2[![JavaScript Style Guide](https://cdn.rawgit.com/standard/standard/master/badge.svg)](https://github.com/standard/standard)
3[![Dependabot](https://badgen.net/dependabot/dependabot/dependabot-core/?icon=dependabot)](https://badgen.net/dependabot/dependabot/dependabot-core/?icon=dependabot)
4[![Actions Status](https://github.com/pioardi/node-pool/workflows/NodeCI/badge.svg)](https://github.com/pioardi/node-pool/actions)
5
6Node pool contains two <a href="https://nodejs.org/api/worker_threads.html#worker_threads_worker_threads">worker-threads </a> pool implementations , you don' t have to deal with worker-threads complexity. <br>
7The first implementation is a static thread pool , with a defined number of threads that are started at creation time .<br>
8The second implementation is a dynamic thread pool with a number of threads started at creation time and other threads created when the load will increase ( with an upper limit ). <br>
9
10## Installation
11```
12npm install node-pool --save
13```
14# Usage
15
16You can implement a worker in a simple way , extending the class ThreadWorker :
17
18```js
19'use strict'
20const { ThreadWorker } = require('node-pool')
21
22class MyWorker extends ThreadWorker {
23 constructor () {
24 super((data) => {
25 // this will be executed in the worker thread, the data will be received by using the execute method
26 return { ok: 1 }
27 })
28 }
29}
30module.exports = new MyWorker()
31```
32
33Instantiate your pool based on your needed :
34
35```js
36'use strict'
37const { FixedThreadPool } = require('node-pool')
38
39// a fixed thread pool
40const pool = new FixedThreadPool(15,
41 './yourWorker.js')
42
43// or a dynamic thread pool
44const pool = new DynamicThreadPool(10, 100,
45 './yourWorker.js')
46pool.emitter.on('FullPool', () => console.log('Pool is full'))
47
48// the execute method signature is the same for both implementations,
49// so you can easy switch from one to another
50pool.execute({}).then(res => {
51 console.log(res)
52}).catch ....
53
54```
55
56<strong> See examples folder for more details.</strong>
57
58## Node versions
59You can use node version 10.x with --experimental-worker flag, or you can use 12.x version <br>
60
61## API
62
63TODO
64
65## License
66
67[MIT](https://github.com/pioardi/node-pool/blob/master/LICENSE)
68