Skip to content

Commit

Permalink
Skip redirecting stdout for Worker threads
Browse files Browse the repository at this point in the history
This breaks running 0x with Workers, because the internal stdio
implementation for Workers currently relies on `process.stdout`
being the originally provided object.
  • Loading branch information
addaleax committed Feb 23, 2019
1 parent 66c12f3 commit 3dd24c4
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions lib/preload/redir-stdout.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
'use strict'
const net = require('net')

const socket = new net.Socket({
fd: 3,
readable: false,
writable: true
})
Object.defineProperty(process, 'stdout', {
configurable: true,
enumerable: true,
get: () => socket
})
let isWorker = false
try {
// Skip redirecting stdout in Worker threads.
isWorker = !require('worker_threads').isMainThread
} catch (e) {}

if (!isWorker) {
const socket = new net.Socket({
fd: 3,
readable: false,
writable: true
})
Object.defineProperty(process, 'stdout', {
configurable: true,
enumerable: true,
get: () => socket
})
}

0 comments on commit 3dd24c4

Please sign in to comment.