funthreads
Advanced tools
Comparing version 2.0.3 to 2.0.4
@@ -1,9 +0,9 @@ | ||
# Contributing to `worker_map` | ||
# Contributing to `funthreads` | ||
Contributions are always welcome. | ||
To contribute, [fork](https://help.github.com/articles/fork-a-repo/) worker_map, commit your changes, & [send a pull request](https://help.github.com/articles/using-pull-requests/). | ||
To contribute, [fork](https://help.github.com/articles/fork-a-repo/) funthreads, commit your changes, & [send a pull request](https://help.github.com/articles/using-pull-requests/). | ||
## Feature Requests | ||
Feature requests should be submitted in the [issue tracker](https://github.com/nairihar/worker_map/issues), with a description of | ||
Feature requests should be submitted in the [issue tracker](https://github.com/nairihar/funthreads/issues), with a description of | ||
the expected behavior & use case. | ||
@@ -10,0 +10,0 @@ |
{ | ||
"name": "funthreads", | ||
"version": "2.0.3", | ||
"version": "2.0.4", | ||
"description": "A lightweight tool built on top of Node.js worker_threads, enabling multithreading.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -113,4 +113,4 @@  | ||
async function read() { | ||
const modules = new ThreadModules('fs/promises', 'test', 'path', ...); | ||
const content = await executeInThread(task, modules); | ||
const requiredModules = new ThreadModules('fs/promises', 'test', 'path', ...); | ||
const content = await executeInThread(task, requiredModules); | ||
console.log(content); | ||
@@ -122,2 +122,4 @@ } | ||
The `ThreadModules` class lets you set up modules for the thread. Just provide it as the second argument, and you'll have access to the libraries through the `modules` object. | ||
The `ThreadModules` class lets you set up modules for the thread. You can provide it only thorough the second argument, and you'll have access to the libraries through the `modules` object. | ||
You should only provide the `ThreadModules` type of object once through the second parameter. Attempting to provide it multiple times will result in an error. Additionally, avoid returning the `modules` object from the task function, as it will also lead to errors. |
@@ -11,5 +11,11 @@ const startWorker = require('./worker/executor'); | ||
exports.executeInThread = (task, threadModules, ...args) => { | ||
let modules; let | ||
params; | ||
let params; | ||
let modules; | ||
const moduleArg = args.find((arg) => arg instanceof ThreadModules); | ||
if (moduleArg) { | ||
throw new Error('ThreadModules type of object should be provided only through the second argument!'); | ||
} | ||
if (threadModules instanceof ThreadModules) { | ||
@@ -16,0 +22,0 @@ modules = threadModules.names; |
@@ -15,4 +15,5 @@ const generateWorkerCode = (func) => ` | ||
const task = ${func}; | ||
const modules = loadModules(workerData.workerModules); | ||
const res = task(...workerData.workerParams, modules); | ||
const res = workerData.workerModules | ||
? task(loadModules(workerData.workerModules), ...workerData.workerParams) | ||
: task(...workerData.workerParams); | ||
const data = (res instanceof Promise) ? await res : res; | ||
@@ -19,0 +20,0 @@ parentPort.postMessage({ data }); |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
14205
141
123
1