本文整理匯總了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')
})