nestworker 1.1.2 → 1.1.3
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 +17 -10
- package/package.json +11 -1
package/README.md
CHANGED
|
@@ -49,10 +49,6 @@ $ npm i nestworker
|
|
|
49
49
|
- [Error handling](https://github.com/VaheHak/nestworker/blob/master/examples/error-handling.ts)
|
|
50
50
|
- [Use modules inside the thread](https://github.com/VaheHak/nestworker/blob/master/examples/modules-in-thread.ts)
|
|
51
51
|
|
|
52
|
-
## Contributing
|
|
53
|
-
|
|
54
|
-
See the [contributing guide](https://github.com/VaheHak/nestworker/blob/master/CONTRIBUTING.md) for detailed instructions on how to get started with our project.
|
|
55
|
-
|
|
56
52
|
## API
|
|
57
53
|
|
|
58
54
|
### `executeInThread(task, { args: any[] }`
|
|
@@ -90,15 +86,15 @@ In this example, we're reading a file in a separate thread and returning the dat
|
|
|
90
86
|
```ts
|
|
91
87
|
import { executeInThread } from 'nestworker';
|
|
92
88
|
|
|
93
|
-
async function task(
|
|
89
|
+
async function task(filename: string) {
|
|
94
90
|
// Closure doesn't work here
|
|
95
91
|
const { readFile } = await import('fs/promises');
|
|
96
|
-
const content = await readFile(
|
|
92
|
+
const content = await readFile(filename);
|
|
97
93
|
return content.toString();
|
|
98
94
|
}
|
|
99
95
|
|
|
100
96
|
async function read() {
|
|
101
|
-
const content = await executeInThread(task,
|
|
97
|
+
const content = await executeInThread(task, { args: [filename] });
|
|
102
98
|
console.log(content);
|
|
103
99
|
}
|
|
104
100
|
|
|
@@ -111,7 +107,7 @@ There is also another option if you don't want to use `import` inside the functi
|
|
|
111
107
|
import { executeInThread } from 'nestworker';
|
|
112
108
|
|
|
113
109
|
// this will be executed in a dedicated thread
|
|
114
|
-
async function task(modules:
|
|
110
|
+
async function task(modules: { 'fs/promises': typeof import('fs/promises') }) {
|
|
115
111
|
// Closure doesn't work here
|
|
116
112
|
const { readFile } = modules['fs/promises'];
|
|
117
113
|
|
|
@@ -131,6 +127,17 @@ async function read() {
|
|
|
131
127
|
read();
|
|
132
128
|
```
|
|
133
129
|
|
|
134
|
-
The `
|
|
130
|
+
The `threadModules` parameter is an array of strings that represent the `modules` you want to use in the thread.
|
|
131
|
+
The `modules` will be imported and passed to the task function `first argument` as an object.
|
|
132
|
+
|
|
133
|
+
## Contributing
|
|
134
|
+
|
|
135
|
+
See the [contributing guide](https://github.com/VaheHak/nestworker/blob/master/CONTRIBUTING.md) for detailed instructions on how to get started with our project.
|
|
136
|
+
|
|
137
|
+
## Author
|
|
138
|
+
|
|
139
|
+
Vahe Hakobyan: [Telegram](https://t.me/vahe_hak)
|
|
140
|
+
|
|
141
|
+
## License
|
|
135
142
|
|
|
136
|
-
|
|
143
|
+
Licensed under [MIT](https://github.com/VaheHak/nestworker/blob/master/LICENSE).
|
package/package.json
CHANGED
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nestworker",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
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,
|
|
7
7
|
"license": "MIT",
|
|
8
|
+
"licenses": [
|
|
9
|
+
{
|
|
10
|
+
"type": "MIT",
|
|
11
|
+
"url": "https://opensource.org/licenses/MIT"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"type": "MIT",
|
|
15
|
+
"url": "https://github.com/VaheHak/nestworker/blob/master/LICENSE"
|
|
16
|
+
}
|
|
17
|
+
],
|
|
8
18
|
"scripts": {
|
|
9
19
|
"prebuild": "rimraf dist",
|
|
10
20
|
"build": "nest build",
|