1- /**!
2- * sendmessage - index.js
3- *
4- * Copyright(c) fengmk2 and other contributors.
5- * MIT Licensed
6- *
7- * Authors:
8- * fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
9- */
1+ const { isMainThread, parentPort } = require ( 'worker_threads' ) ;
102
11- 'use strict' ;
12-
13- /**
14- * Module dependencies.
15- */
16- var { isMainThread, parentPort } = require ( 'worker_threads' ) ;
17-
18- var IS_NODE_DEV_RUNNER = / n o d e \- d e v $ / . test ( process . env . _ || '' ) ;
3+ let IS_NODE_DEV_RUNNER = / n o d e \- d e v $ / . test ( process . env . _ || '' ) ;
194if ( ! IS_NODE_DEV_RUNNER && process . env . IS_NODE_DEV_RUNNER ) {
205 IS_NODE_DEV_RUNNER = true ;
216}
@@ -38,24 +23,24 @@ module.exports = function send(child, message) {
3823
3924 // child is worker
4025 if ( typeof child . postMessage === 'function' ) {
41- return child . postMessage ( message )
26+ return child . postMessage ( message ) ;
4227 }
4328 // in worker thread
4429 if ( ! isMainThread ) {
45- return parentPort . postMessage ( message )
30+ return parentPort . postMessage ( message ) ;
4631 }
4732
4833 // cluster.fork(): child.process is process
4934 // childprocess.fork(): child is process
50- var connected = child . process ? child . process . connected : child . connected ;
35+ const connected = child . process ? child . process . connected : child . connected ;
5136
5237 if ( connected ) {
5338 return child . send ( message ) ;
5439 }
5540
5641 // just log warnning message
57- var pid = child . process ? child . process . pid : child . pid ;
58- var err = new Error ( 'channel closed' ) ;
42+ const pid = child . process ? child . process . pid : child . pid ;
43+ const err = new Error ( 'channel closed' ) ;
5944 console . warn ( '[%s][sendmessage] WARN pid#%s channel closed, nothing send\nstack: %s' ,
6045 Date ( ) , pid , err . stack ) ;
6146} ;
0 commit comments