thread-stream
Advanced tools
Comparing version 0.8.1 to 0.9.0
21
index.js
@@ -131,5 +131,2 @@ 'use strict' | ||
break | ||
case 'FINISH': | ||
this.emit('finish') | ||
break | ||
default: | ||
@@ -214,2 +211,4 @@ throw new Error('this should not happen: ' + msg.code) | ||
let read = Atomics.load(this._state, READ_INDEX) | ||
// process._rawDebug('writing index') | ||
@@ -219,2 +218,18 @@ Atomics.store(this._state, WRITE_INDEX, -1) | ||
Atomics.notify(this._state, WRITE_INDEX) | ||
// Wait for the process to complete | ||
let spins = 0 | ||
while (read !== -1) { | ||
// process._rawDebug(`read = ${read}`) | ||
Atomics.wait(this._state, READ_INDEX, read, 1000) | ||
read = Atomics.load(this._state, READ_INDEX) | ||
if (++spins === 10) { | ||
throw new Error('end() took too long (10s)') | ||
} | ||
} | ||
process.nextTick(() => { | ||
this.emit('finish') | ||
}) | ||
// process._rawDebug('end finished...') | ||
@@ -221,0 +236,0 @@ } |
@@ -21,9 +21,7 @@ 'use strict' | ||
destination.on('finish', function () { | ||
parentPort.postMessage({ | ||
code: 'FINISH' | ||
}) | ||
}) | ||
destination.on('close', function () { | ||
// process._rawDebug('worker close emitted') | ||
const end = Atomics.load(state, WRITE_INDEX) | ||
Atomics.store(state, READ_INDEX, end) | ||
Atomics.notify(state, READ_INDEX) | ||
setImmediate(() => { | ||
@@ -64,4 +62,2 @@ process.exit(0) | ||
if (end === -1) { | ||
Atomics.store(state, READ_INDEX, end) | ||
Atomics.notify(state, READ_INDEX) | ||
// process._rawDebug('end') | ||
@@ -68,0 +64,0 @@ destination.end() |
{ | ||
"name": "thread-stream", | ||
"version": "0.8.1", | ||
"version": "0.9.0", | ||
"description": "A streaming way to send data to a Node.js Worker Thread", | ||
@@ -9,3 +9,3 @@ "main": "index.js", | ||
"fastbench": "^1.0.1", | ||
"husky": "^5.1.3", | ||
"husky": "^6.0.0", | ||
"sonic-boom": "^1.3.2", | ||
@@ -17,2 +17,3 @@ "standard": "^16.0.3", | ||
"test": "standard && tap --no-check-coverage test/*.test.*js", | ||
"test:ci": "standard && tap \"test/**/*.test.*js\" --no-check-coverage --coverage-report=lcovonly", | ||
"prepare": "husky install" | ||
@@ -19,0 +20,0 @@ }, |
# thread-stream | ||
[![npm version](https://img.shields.io/npm/v/thread-stream)](https://www.npmjs.com/package/thread-stream) | ||
[![Build Status](https://img.shields.io/github/workflow/status/pinojs/thread-stream/CI)](https://github.com/pinojs/thread-stream/actions) | ||
[![Known Vulnerabilities](https://snyk.io/test/github/pinojs/thread-stream/badge.svg)](https://snyk.io/test/github/pinojs/thread-stream) | ||
[![Coverage Status](https://coveralls.io/repos/github/pinojs/thread-stream/badge.svg?branch=master)](https://coveralls.io/github/pinojs/thread-stream?branch=master) | ||
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/) | ||
@@ -56,4 +61,8 @@ A streaming way to send data to a Node.js Worker Thread. | ||
Make sure that the stream emits `'close'` when the stream completes. | ||
This can usually be achieved by passing the [`autoDestroy: true`](https://nodejs.org/api/stream.html#stream_new_stream_writable_options) | ||
flag your stream classes. | ||
## License | ||
MIT |
@@ -8,2 +8,3 @@ 'use strict' | ||
return new Writable({ | ||
autoDestroy: true, | ||
write (chunk, enc, cb) { | ||
@@ -10,0 +11,0 @@ port.postMessage(chunk.toString()) |
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
36868
27
1190
68
11