Node.js – process.channel 屬性
當一個節點程序是透過一個 IPC 通道生成的,process.channel 屬性提供了對該 IPC 通道的引用。如果不存在 IPC 通道,那麼此屬性為未定義。
語法
process.channel
示例 1
建立兩個檔案 "channel.js" 和 "util.js",並複製以下程式碼片段。建立檔案後,使用命令 "node channels.js" 和 "node util.js" 執行程式碼。
channel.js
// process.channel Property Demo Example
// Importing the process modules
const cp = require('child_process');
// Getting reference to the child
const process = cp.fork(`${__dirname}/util.js`);
// Sending the below message to child
process.send({ msg: 'Welcome to Tutorials Point' });
console.log(process.channel)util.js
// This child will consume the message through channel
process.on('message', (m) => {
console.log('CHILD got message:', m);
process.exit()
});輸出
Pipe {
buffering: false,
pendingHandle: null,
onread: [Function],
sockets: { got: {}, send: {} } }
CHILD got message: { msg: 'Welcome to Tutorials Point' }示例 2
我們再看一個示例。
// process.channel Property Demo Example
// Importing the process modules
const process = require('process');
// Checking the process channel
if(process.channel)
console.log("Process Channel exist")
else
console.log("Process Channel doesn't exist")輸出
Process Channel doesn't exist
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP