Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

thread-stream

Package Overview
Dependencies
Maintainers
4
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

thread-stream - npm Package Compare versions

Comparing version 2.0.1 to 2.1.0

test/emit-event.js

7

index.js

@@ -166,2 +166,9 @@ 'use strict'

break
case 'EVENT':
if (Array.isArray(msg.args)) {
stream.emit(msg.name, ...msg.args)
} else {
stream.emit(msg.name, msg.args)
}
break
default:

@@ -168,0 +175,0 @@ destroy(stream, new Error('this should not happen: ' + msg.code))

2

package.json
{
"name": "thread-stream",
"version": "2.0.1",
"version": "2.1.0",
"description": "A streaming way to send data to a Node.js Worker Thread",

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

@@ -87,4 +87,29 @@ # thread-stream

### Emit events
You can emit events on the ThreadStream from your worker using [`worker.parentPort.postMessage()`](https://nodejs.org/api/worker_threads.html#workerparentport).
The message (JSON object) must have the following data structure:
```js
parentPort.postMessage({
code: 'EVENT',
name: 'eventName',
args: ['list', 'of', 'args', 123, new Error('Boom')]
})
```
On your ThreadStream, you can add a listener function for this event name:
```js
const stream = new ThreadStream({
filename: join(__dirname, 'worker.js'),
workerData: {},
})
stream.on('eventName', function (a, b, c, n, err) {
console.log('received:', a, b, c, n, err) // received: list of args 123 Error: Boom
})
```
## License
MIT
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc