Socket
Socket
Sign inDemoInstall

node-worker-threads-pool

Package Overview
Dependencies
0
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.4.2 to 1.4.3

15

index.d.ts

@@ -7,8 +7,13 @@ /// <reference types="node" />

type TaskFunc<ParamType, ResultType> =
| (() => Promise<ResultType>)
| (() => ResultType)
| ((param: ParamType) => Promise<ResultType>)
| ((param: ParamType) => ResultType);
type TaskFuncThis<WorkerData = any> = {
workerData: WorkerData;
require: NodeRequire;
};
type TaskFunc<ParamType, ResultType, WorkerData = any> =
| ((this: TaskFuncThis<WorkerData>) => Promise<ResultType>)
| ((this: TaskFuncThis<WorkerData>) => ResultType)
| ((this: TaskFuncThis<WorkerData>, param: ParamType) => Promise<ResultType>)
| ((this: TaskFuncThis<WorkerData>, param: ParamType) => ResultType);
type CommonWorkerSettings = {

@@ -15,0 +20,0 @@ /**

{
"name": "node-worker-threads-pool",
"version": "1.4.2",
"version": "1.4.3",
"description": "Simple worker threads pool using Node's worker_threads module. Compatible with ES6+ Promise, Async/Await.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -351,2 +351,31 @@ # node-worker-threads-pool

## Integration with Webpack
If you are using webpack in your project and want to import third-party libraries in task function, please use `this.require`:
```js
const staticPool = new StaticPool({
size: 4,
task() {
const lib = this.require("lib");
// ...
},
});
```
```js
const dynamicPool = new DynamicPool(4);
dynamicPool
.exec({
task() {
const lib = this.require("lib");
// ...
},
})
.then((result) => {
// ...
});
```
[cloneable data]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm

@@ -353,0 +382,0 @@ [resourcelimits]: https://nodejs.org/api/worker_threads.html#worker_threads_worker_resourcelimits

@@ -27,3 +27,3 @@ /**

const task = vm.runInThisContext(code);
const container = { task, workerData };
const container = { task, workerData, require };
const result = await container.task(param);

@@ -30,0 +30,0 @@ parentPort.postMessage(result);

@@ -16,2 +16,3 @@ const { Pool } = require("./pool");

workerData,
require,
task: ${createCode(fn)}

@@ -18,0 +19,0 @@ };

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc