diff options
author | Joyee Cheung <joyeec9h3@gmail.com> | 2019-03-12 00:42:31 +0800 |
---|---|---|
committer | Joyee Cheung <joyeec9h3@gmail.com> | 2019-03-19 21:00:48 +0800 |
commit | 9868d544119409750231d4a5ff94a356385b126d (patch) | |
tree | 6cfbf191dc5a505b6f34c4a62878224b91d5f011 /lib/internal/process | |
parent | 927f29d244e95a38816c305d82d290bd10b5938b (diff) | |
download | android-node-v8-9868d544119409750231d4a5ff94a356385b126d.tar.gz android-node-v8-9868d544119409750231d4a5ff94a356385b126d.tar.bz2 android-node-v8-9868d544119409750231d4a5ff94a356385b126d.zip |
worker: create per-Environment message port after bootstrap
PR-URL: https://github.com/nodejs/node/pull/26593
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib/internal/process')
-rw-r--r-- | lib/internal/process/worker_thread_only.js | 29 |
1 files changed, 11 insertions, 18 deletions
diff --git a/lib/internal/process/worker_thread_only.js b/lib/internal/process/worker_thread_only.js index 2cc52cbf01..b6529e4344 100644 --- a/lib/internal/process/worker_thread_only.js +++ b/lib/internal/process/worker_thread_only.js @@ -2,32 +2,25 @@ // This file contains process bootstrappers that can only be // run in the worker thread. -const { - getEnvMessagePort -} = internalBinding('worker'); const { - kWaitingStreams, - ReadableWorkerStdio, - WritableWorkerStdio + createWorkerStdio } = require('internal/worker/io'); const { codes: { ERR_WORKER_UNSUPPORTED_OPERATION } } = require('internal/errors'); -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'); +let workerStdio; +function lazyWorkerStdio() { + if (!workerStdio) workerStdio = createWorkerStdio(); + return workerStdio; +} +function createStdioGetters() { return { - getStdout() { return workerStdio.stdout; }, - getStderr() { return workerStdio.stderr; }, - getStdin() { return workerStdio.stdin; } + getStdout() { return lazyWorkerStdio().stdout; }, + getStderr() { return lazyWorkerStdio().stderr; }, + getStdin() { return lazyWorkerStdio().stdin; } }; } @@ -55,7 +48,7 @@ function unavailable(name) { } module.exports = { - initializeWorkerStdio, + createStdioGetters, unavailable, wrapProcessMethods }; |