-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1f21faa
commit 13d3c8f
Showing
4 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use strict' | ||
|
||
const { Writable } = require('stream') | ||
const parentPort = require('worker_threads').parentPort | ||
|
||
async function run () { | ||
return new Writable({ | ||
autoDestroy: true, | ||
write (chunk, enc, cb) { | ||
if (parentPort) { | ||
parentPort.postMessage({ | ||
code: 'EVENT', | ||
name: 'socketError', | ||
args: ['list', 'of', 'args', 123, new Error('unable to write data to the TCP socket')] | ||
}) | ||
} | ||
cb() | ||
} | ||
}) | ||
} | ||
|
||
module.exports = run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use strict' | ||
|
||
const { test } = require('tap') | ||
const { join } = require('path') | ||
const ThreadStream = require('..') | ||
|
||
test('event propagate', function (t) { | ||
const stream = new ThreadStream({ | ||
filename: join(__dirname, 'emit-event.js'), | ||
workerData: {}, | ||
sync: true | ||
}) | ||
stream.on('socketError', function (a, b, c, n, error) { | ||
t.same(a, 'list') | ||
t.same(b, 'of') | ||
t.same(c, 'args') | ||
t.same(n, 123) | ||
t.same(error, new Error('unable to write data to the TCP socket')) | ||
t.end() | ||
}) | ||
stream.write('hello') | ||
stream.end() | ||
}) |