本文整理匯總了TypeScript中xev.emit函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript emit函數的具體用法?TypeScript emit怎麽用?TypeScript emit使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了emit函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: publish
function publish(channel: string, type: string, value?: any): void {
const message = type == null ? value : value == null ?
{ type: type } :
{ type: type, body: value };
ev.emit(channel, message);
}
示例2: switch
connection.on('message', async data => {
const msg = JSON.parse(data.utf8Data);
switch (msg.type) {
case 'requestLog':
ev.once('notesStatsLog:' + msg.id, statsLog => {
connection.send(JSON.stringify({
type: 'statsLog',
body: statsLog
}));
});
ev.emit('requestNotesStatsLog', msg.id);
break;
}
});
示例3: tick
async function tick() {
const cpu = await cpuUsage();
const usedmem = await usedMem();
const totalmem = await totalMem();
const disk = diskusage.checkSync(os.platform() == 'win32' ? 'c:' : '/');
const stats = {
cpu_usage: cpu,
mem: {
total: totalmem,
used: usedmem
},
disk,
os_uptime: os.uptime(),
process_uptime: process.uptime()
};
ev.emit('serverStats', stats);
log.push(stats);
if (log.length > 50) log.shift();
}
示例4:
ev.on('requestServerStatsLog', id => {
ev.emit('serverStatsLog:' + id, log.toArray());
});
示例5: publish
publish(channelName: string, message: any): void {
this.parentEmitter.emit(channelName, message);
}