async-transforms
Advanced tools
Comparing version 1.0.7 to 1.0.8
{ | ||
"name": "async-transforms", | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"description": "Asynchronous stream transforms", | ||
@@ -23,4 +23,4 @@ "type": "module", | ||
"devDependencies": { | ||
"chai": "^4.2.0", | ||
"mocha": "^7.1.1", | ||
"@types/node": "^15.0.3", | ||
"ava": "^3.15.0", | ||
"rollup": "^2.1.0" | ||
@@ -30,7 +30,4 @@ }, | ||
"prepublishOnly": "bash build.sh", | ||
"test": "mocha" | ||
}, | ||
"optionalDependencies": { | ||
"@types/node": "^14.14.20" | ||
"test": "ava" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
[![Build](https://api.travis-ci.org/samthor/async-transforms.svg?branch=master)](https://travis-ci.org/samthor/async-transforms) | ||
[![Node.JS CI](https://github.com/samthor/async-transforms/actions/workflows/tests.yml/badge.svg)](https://github.com/samthor/async-transforms/actions/workflows/tests.yml) | ||
@@ -77,11 +77,10 @@ Asynchronous stream transforms for Node. | ||
const compilationPool = pool(path.resolve('./compile.js')); | ||
const asyncCompile = pool(path.resolve('./compile.js'), {tasks: 2}); | ||
// use directly | ||
compilationPool(123, {tasks: 2}) | ||
.then((result) => console.info('result from passing value to worker', result)); | ||
const result = await asyncCompile('input', 'all', 'args', 'are', 'passed'); | ||
// or as part of a transform | ||
stream.Readable.from([object1, object2]) | ||
.pipe(transforms.map(compilationPool)) | ||
.pipe(transforms.map(asyncCompile)) | ||
.pipe(transforms.map(() => { | ||
@@ -93,6 +92,9 @@ // do something with the result | ||
The pool invokes the default export (or `module.exports` for CJS) of the target file. | ||
By default, it utilizes 75% of your local CPUs, but set `tasks` to control this—use a fraction from 0-1 to set a ratio, and higher for absolute. | ||
By default, it creates a maximum number of workers equal to 75% of your local CPUs, but set `tasks` to control this—use a fraction from 0-1 to set a ratio, and higher integers for an absolute number. | ||
You can also specify `minTasks` to always keep a number of hot workers around. | ||
This number can only be an integer, and defaults to 1. | ||
Use this for CPU-bound tasks like JS minification. | ||
This doesn't really belong in this module. |
@@ -43,2 +43,2 @@ | ||
*/ | ||
export function toArray(): {stream: stream.Transform, promise: Promise<Iterable<any>>}; | ||
export function toArray(): {stream: stream.Transform, promise: Promise<any[]>}; |
@@ -162,3 +162,3 @@ import stream from 'stream'; | ||
* | ||
* @param {function(!Array<?>): (!Array<?>|!Promise<!Array<?>>)} handler | ||
* @param {function(any[]): (Iterable<any>|Promise<Iterable<any>>)} handler | ||
* @return {!stream.Transform} | ||
@@ -165,0 +165,0 @@ */ |
@@ -54,2 +54,3 @@ import worker from 'worker_threads'; | ||
let preparingNewWorker = false; | ||
let activeWorkers = 0; | ||
@@ -67,2 +68,3 @@ | ||
} | ||
preparingNewWorker = false; | ||
releaseWorker(w); | ||
@@ -89,3 +91,4 @@ }); | ||
// Start a new worker, but still push the work onto the queue for when it's ready. | ||
if (activeWorkers < o.tasks) { | ||
if (!preparingNewWorker && activeWorkers < o.tasks) { | ||
preparingNewWorker = true; | ||
prepareWorker(); | ||
@@ -92,0 +95,0 @@ } |
@@ -32,2 +32,4 @@ /** | ||
}); | ||
parentPort.postMessage({ok: false}); | ||
throw error; | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
42863
0
14
840
99