Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
pxgo committed Jan 4, 2020
1 parent a73d0a3 commit 7564219
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
24 changes: 20 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
## node-threads-pool
nodejs threads pool
[david-image]: https://img.shields.io/david/pengxigua/node-threads-pool.svg?style=flat-square
[david-url]: https://david-dm.org/pengxigua/node-threads-pool
[node-image]: https://img.shields.io/badge/node.js-%3E=_12-green.svg?style=flat-square
[node-url]: http://nodejs.org/download/
[download-image]: https://img.shields.io/npm/dm/node-threads-pool.svg?style=flat-square
[download-url]: https://npmjs.org/package/node-threads-pool
[license-image]: https://img.shields.io/npm/l/node-threads-pool.svg

### Install
```
npm install node-threads-pool
```

### Example
### Usage
```
//app.js
Expand All @@ -33,9 +39,19 @@ tp.run("./thread.js", {
const {workerData, parentPort} = require("worker_threads");
const {n} = workerData;
const fn = (n) => {
if(n < 3) return n - 1;
if(n < 3) return 1;
return fn(n-2) + fn(n-1);
}
parentPort.postMessage(fn(n));
```
```

### Methods

#### new TP([number]); // number: the maximum number of threads. The default value is 1.
Create a thread pool instance.


#### TP.run(filename[, options]); // options: [View here](https://nodejs.org/dist/latest-v12.x/docs/api/worker_threads.html#worker_threads_new_worker_filename_options)

Run a file in a child thread.
2 changes: 1 addition & 1 deletion test/app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const TP = require("../index");
const tp = new TP(20);
const tp = new TP(10);

for(var i = 0; i < 1000; i++) {
tp.run(__dirname + "/thread.js", {
Expand Down
2 changes: 1 addition & 1 deletion test/thread.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const {workerData, parentPort} = require("worker_threads");
const {n, index} = workerData;
const fn = (n) => {
if(n < 3) return n - 1;
if(n < 3) return 1;
return fn(n-2) + fn(n-1);
}
parentPort.postMessage({
Expand Down

0 comments on commit 7564219

Please sign in to comment.