Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
handleMessage(message, worker) {
consola.trace((this.alias || this.id) + ' received message', message instanceof Object ? JSON.stringify(message) : message)
const { receiverId } = message
if (receiverId !== undefined) {
if (
receiverId === this.id ||
receiverId === this.alias ||
(this.isMaster && receiverId === this.masterId)
) {
this.callService(message, worker)
} else if (this.isMaster && this.proxies[receiverId]) {
this.proxies[receiverId].send(message)
} else {
consola.warn(`Proxy ${receiverId} not registered`)
}
}
}
sendMessage(message) {
if (!this.isMaster && !cluster.isMaster) {
consola.trace(`sending message through process`, JSON.stringify(message))
process.send(message)
} else if (!this.isMaster && this.masterRef) {
return new Promise((resolve) => {
consola.trace(`sending message through promise`, JSON.stringify(message))
const ref = {}
if (message.serviceId === '_register') {
ref.send = (message) => {
this.handleMessage(message)
}
}
this.masterRef.handleMessage(message, ref)
resolve()
})
return new Promise((resolve) => {
consola.trace(`sending message through promise`, JSON.stringify(message))
const ref = {}
if (message.serviceId === '_register') {
ref.send = (message) => {
this.handleMessage(message)
}
}
this.masterRef.handleMessage(message, ref)
resolve()
})
} else if (this.proxies[message.receiverId]) {