diff options
Diffstat (limited to 'lib/internal/process')
-rw-r--r-- | lib/internal/process/main_thread_only.js | 10 | ||||
-rw-r--r-- | lib/internal/process/stdio.js | 26 | ||||
-rw-r--r-- | lib/internal/process/worker_thread_only.js | 51 |
3 files changed, 41 insertions, 46 deletions
diff --git a/lib/internal/process/main_thread_only.js b/lib/internal/process/main_thread_only.js index 862194ae46..42579e9da8 100644 --- a/lib/internal/process/main_thread_only.js +++ b/lib/internal/process/main_thread_only.js @@ -16,15 +16,6 @@ const { validateString } = require('internal/validators'); -const { - setupProcessStdio, - getMainThreadStdio -} = require('internal/process/stdio'); - -function setupStdio() { - setupProcessStdio(getMainThreadStdio()); -} - // The execution of this function itself should not cause any side effects. function wrapProcessMethods(binding) { function chdir(directory) { @@ -174,7 +165,6 @@ function setupChildProcessIpcChannel() { } module.exports = { - setupStdio, wrapProcessMethods, setupSignalHandlers, setupChildProcessIpcChannel, diff --git a/lib/internal/process/stdio.js b/lib/internal/process/stdio.js index 5e9ff6b260..bf5f6df15f 100644 --- a/lib/internal/process/stdio.js +++ b/lib/internal/process/stdio.js @@ -1,6 +1,5 @@ 'use strict'; -exports.setupProcessStdio = setupProcessStdio; exports.getMainThreadStdio = getMainThreadStdio; function dummyDestroy(err, cb) { cb(err); } @@ -134,31 +133,6 @@ function getMainThreadStdio() { }; } -function setupProcessStdio({ getStdout, getStdin, getStderr }) { - Object.defineProperty(process, 'stdout', { - configurable: true, - enumerable: true, - get: getStdout - }); - - Object.defineProperty(process, 'stderr', { - configurable: true, - enumerable: true, - get: getStderr - }); - - Object.defineProperty(process, 'stdin', { - configurable: true, - enumerable: true, - get: getStdin - }); - - process.openStdin = function() { - process.stdin.resume(); - return process.stdin; - }; -} - function createWritableStdioStream(fd) { var stream; const tty_wrap = internalBinding('tty_wrap'); diff --git a/lib/internal/process/worker_thread_only.js b/lib/internal/process/worker_thread_only.js index 834ba6078f..a9332fb427 100644 --- a/lib/internal/process/worker_thread_only.js +++ b/lib/internal/process/worker_thread_only.js @@ -2,23 +2,54 @@ // This file contains process bootstrappers that can only be // run in the worker thread. +const { + getEnvMessagePort, + threadId +} = internalBinding('worker'); + +const debug = require('util').debuglog('worker'); const { - setupProcessStdio -} = require('internal/process/stdio'); + kWaitingStreams, + ReadableWorkerStdio, + WritableWorkerStdio +} = require('internal/worker/io'); const { - workerStdio + createMessageHandler, + createWorkerFatalExeception } = require('internal/worker'); -function setupStdio() { - setupProcessStdio({ - getStdout: () => workerStdio.stdout, - getStderr: () => workerStdio.stderr, - getStdin: () => workerStdio.stdin - }); +const workerStdio = {}; + +function initializeWorkerStdio() { + const port = getEnvMessagePort(); + port[kWaitingStreams] = 0; + workerStdio.stdin = new ReadableWorkerStdio(port, 'stdin'); + workerStdio.stdout = new WritableWorkerStdio(port, 'stdout'); + workerStdio.stderr = new WritableWorkerStdio(port, 'stderr'); + + return { + getStdout() { return workerStdio.stdout; }, + getStderr() { return workerStdio.stderr; }, + getStdin() { return workerStdio.stdin; } + }; +} + +function setup() { + debug(`[${threadId}] is setting up worker child environment`); + + const port = getEnvMessagePort(); + const publicWorker = require('worker_threads'); + port.on('message', createMessageHandler(publicWorker, port, workerStdio)); + port.start(); + + return { + workerFatalExeception: createWorkerFatalExeception(port) + }; } module.exports = { - setupStdio + initializeWorkerStdio, + setup }; |