本文整理汇总了TypeScript中child_process.ChildProcess.send方法的典型用法代码示例。如果您正苦于以下问题:TypeScript ChildProcess.send方法的具体用法?TypeScript ChildProcess.send怎么用?TypeScript ChildProcess.send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类child_process.ChildProcess
的用法示例。
在下文中一共展示了ChildProcess.send方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
send: r => this.child && this.child.connected && this.child.send(r),
示例2: fork
completedCreation.then(() => {
console.timeEnd('Create DB');
// create the threads that will access the database
let threads:Array<ChildProcess> = new Array<ChildProcess>();
console.log("Creating Threads");
for (let i = 0; i < threadCount; ++i) {
let new_child:ChildProcess;
if (mode == DBMode.RacerTable) {
new_child = fork('./stress-test-racer');
} else if (mode == DBMode.TeamTable) {
new_child = fork('./stress-test-team');
}
new_child.send({
type: 'generate',
teams: teams,
racersATeam: racersATeam,
updateQueryRatio: updateQueryRatio,
thisThreadNum: i,
totalThreads: threadCount,
accessCount: accessCount
});
threads.push(new_child);
}
// run the three tests once after another
async.series([
(callback:(err:Error)=>void) => {
// Wait for all threads to be ready
Promise.all(threads.map(thread=>new Promise((resolve, reject)=> {
thread.once('message', (msg:string) => msg === 'ready' ? resolve() : reject())
}))).then(() => {
console.log('All Threads Ready');
callback(null);
}).catch(() => callback(new Error('Thread Error')));
},
(callback:(err:Error)=>void) => {
console.time("Update from all Threads");
Promise.all(threads.map(thread=>new Promise((resolve, reject)=> {
thread.send('update');
thread.once('message', (msg:string) => msg === 'update' ? resolve() : reject());
}))).then(() => {
console.timeEnd("Update from all Threads");
callback(null);
}).catch(() => callback(new Error('Thread Error')));
},
(callback:(err:Error)=>void) => {
console.time("Query from all Threads");
Promise.all(threads.map(thread=>new Promise((resolve, reject)=> {
thread.send('query');
thread.once('message', (msg:string) => msg === 'query' ? resolve() : reject());
}))).then(()=> {
console.timeEnd("Query from all Threads");
callback(null);
}).catch(() => callback(new Error('Thread Error')));
},
(callback:(err:Error)=>void) => {
console.time("Update and Query from all Threads");
Promise.all(threads.map(thread=>new Promise((resolve, reject)=> {
thread.send('both');
thread.once('message', (msg:string) => msg === 'both' ? resolve() : reject());
}))).then(()=> {
console.timeEnd("Update and Query from all Threads");
callback(null);
}).catch(() => callback(new Error('Thread Error')));
},
(callback:(err:Error)=>void) => {
threads.map((thread:ChildProcess)=>thread.disconnect());
db.close();
callback(null);
}
]);
});
示例3:
const send = r => this.child && this.child.connected && this.child.send(r);