Skip to content

Commit

Permalink
Merge pull request #208 from addaleax/no-redir-on-worker
Browse files Browse the repository at this point in the history
Skip redirecting stdout for Worker threads
  • Loading branch information
mcollina authored Feb 23, 2019
2 parents 66c12f3 + 3dd24c4 commit f919655
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 f919655

Please sign in to comment.