本文整理汇总了TypeScript中node-ipc.IPC类的典型用法代码示例。如果您正苦于以下问题:TypeScript IPC类的具体用法?TypeScript IPC怎么用?TypeScript IPC使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IPC类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: IPC
export const sendMessage = (msg: any): Promise<any> => {
const ipc = new IPC()
ipc.config.appspace = 'ddns.'
ipc.config.id = 'client'
ipc.config.silent = true
return new Promise((resolve, reject) => {
setTimeout(() => {
reject(new Error('Connecting to daemon timeout.'))
}, 3000)
ipc.connectTo('worker', () => {
ipc.of.worker.on('connect', () => {
ipc.of.worker.emit('message', msg)
ipc.of.worker
.on('message', (data) => {
resolve(data)
})
.on('error', (err) => {
reject(err)
})
})
})
}).finally(() => {
ipc.disconnect('worker')
})
}
示例2: Worker
import { Worker } from './Worker'
process.on('uncaughtException', (err) => {
logger.error(err.message)
})
process.on('unhandledRejection', (err) => {
logger.error(err.message)
})
const worker = new Worker()
const ipMonitor: IpMonitor = new IpMonitor()
ipMonitor.on('change', (ip) => {
worker.sync(ip)
})
const ipc = new IPC()
ipc.config.appspace = 'ddns.'
ipc.config.id = 'worker'
ipc.config.silent = true
ipc.serve(() => {
ipc.server.on('message', (data, socket) => {
try {
const res = worker.onMessage(data)
ipc.server.emit(socket, 'message', res)
} catch (err) {
ipc.server.emit(socket, 'message', err.message)
} finally {
if (worker.getActiveDomainCount() > 0) {
ipMonitor.start()
} else {
ipMonitor.stop()
示例3: resolve
return new Promise<boolean>((resolve) => {
pingIpc.connectTo('worker', () => {
pingIpc.of.worker.on('connect', () => {
resolve(true)
})
pingIpc.of.worker.on('error', () => {
resolve(false)
})
})
}).finally(() => {
示例4: Promise
return new Promise((resolve, reject) => {
setTimeout(() => {
reject(new Error('Connecting to daemon timeout.'))
}, 3000)
ipc.connectTo('worker', () => {
ipc.of.worker.on('connect', () => {
ipc.of.worker.emit('message', msg)
ipc.of.worker
.on('message', (data) => {
resolve(data)
})
.on('error', (err) => {
reject(err)
})
})
})
}).finally(() => {
示例5:
}).finally(() => {
ipc.disconnect('worker')
})