nestworker 1.1.0 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -4
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|

|
|
2
2
|

|
|
3
|
+

|
|
3
4
|

|
|
5
|
+

|
|
6
|
+

|
|
7
|
+

|
|
8
|
+

|
|
9
|
+

|
|
10
|
+

|
|
11
|
+
|
|
4
12
|
|
|
5
13
|
# nestworker
|
|
6
14
|
A simple library that provides an abstraction for the Node.js `worker_threads` module. You can run your function in a dedicated thread by working with Promises.
|
|
@@ -11,11 +19,11 @@ import { executeInThread } from 'nestworker';
|
|
|
11
19
|
|
|
12
20
|
async function calculate(): Promise<void> {
|
|
13
21
|
const values = await Promise.all([
|
|
14
|
-
executeInThread(() => 2 ** 10),
|
|
22
|
+
executeInThread(() => 2 ** 10), // this doesn't block the main thread
|
|
15
23
|
executeInThread(() => 3 ** 10),
|
|
16
24
|
]);
|
|
17
25
|
|
|
18
|
-
console.log(values);
|
|
26
|
+
console.log(values); // [1024, 59049]
|
|
19
27
|
}
|
|
20
28
|
|
|
21
29
|
calculate();
|
|
@@ -47,7 +55,7 @@ See the [contributing guide](https://github.com/VaheHak/nestworker/blob/master/C
|
|
|
47
55
|
|
|
48
56
|
## API
|
|
49
57
|
|
|
50
|
-
### executeInThread(task, { args: any[] }
|
|
58
|
+
### `executeInThread(task, { args: any[] }`
|
|
51
59
|
Runs the specified function in a separate thread.
|
|
52
60
|
|
|
53
61
|
#### Parameters
|
|
@@ -57,7 +65,7 @@ Runs the specified function in a separate thread.
|
|
|
57
65
|
- Parameter cann't be a function.
|
|
58
66
|
|
|
59
67
|
```ts
|
|
60
|
-
const task = function(
|
|
68
|
+
const task = function(a: number, b: object, c: boolean) { ... };
|
|
61
69
|
executeInThread(task, { args: [1, {}, true] })
|
|
62
70
|
```
|
|
63
71
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nestworker",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "A lightweight tool built on top of Node.js worker_threads, enabling multithreading.",
|
|
5
5
|
"author": "Vahe Hakobyan",
|
|
6
6
|
"private": false,
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"homepage": "https://github.com/VaheHak/nestworker#readme",
|
|
35
35
|
"repository": {
|
|
36
36
|
"type": "git",
|
|
37
|
-
"url": "
|
|
37
|
+
"url": "https://github.com/VaheHak/nestworker.git"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@nestjs/common": "10.3.8"
|