Skip to content

Commit

Permalink
update wording
Browse files Browse the repository at this point in the history
  • Loading branch information
dubfib committed Aug 21, 2023
1 parent af1282e commit 6ec6b59
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -20,7 +20,7 @@ npm install --save thweads
## Usage
```js
const Thweads = require('thweads');
const thweads = new Thweads({ threads: 4 });
const thweads = new Thweads({ thweads: 4 });
//or Thweads() to automatically set thweads

thweads.addAction(async () => {
Expand All @@ -31,4 +31,4 @@ thweads.addAction(async () => {
thweads.startActions();
```

##### © Copyright 2023 dubfib - MIT License
##### © Copyright 2023 dubfib - MIT License
8 changes: 4 additions & 4 deletions index.js
@@ -1,8 +1,8 @@
const { Worker, isMainThread, parentPort, workerData } = require('worker_threads');

module.exports = class Thweads {
constructor({ threads } = {}) {
this.threads = threads || Math.max(1, Math.floor(require('os').cpus().length / 2));
constructor({ thweads } = {}) {
this.thweads = thweads || Math.max(1, Math.floor(require('os').cpus().length / 2));
this.actions = [];
this.completedTasks = 0;
}
Expand All @@ -27,9 +27,9 @@ module.exports = class Thweads {
return;
};

const actionsPerThread = Math.ceil(this.actions.length / this.threads);
const actionsPerThread = Math.ceil(this.actions.length / this.thweads);

for (let i = 0; i < this.threads; i++) {
for (let i = 0; i < this.thweads; i++) {
const start = i * actionsPerThread;
const end = start + actionsPerThread;
const threadActions = this.actions.slice(start, end).map(fn => fn.toString());
Expand Down

0 comments on commit 6ec6b59

Please sign in to comment.