1.0.17 • Published 1 year ago

@david.uhlir/ipc-method v1.0.17

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

IPC Method calling

Helper to send message over IPC as calling of methods. IpcMethodHandler is class thas provides both directions of communications. Receiver in this case is object, where keys are name of actions, what is posible to call from other handlers. All connected handlers must be on same topics (arrays of topics must be same) to connect them together. Every each call will returns IpcMethodResult, which allows you to handle multiple results (as receivers can be more than one).

This is complete example with one fork and master process.

import { IpcMethodHandler } from '@david.uhlir/ipc-method'
import * as cluster from 'cluster'

const masterReceiver = {
  testMaster: async () => console.log(process.pid, 'Hello in master'),
}

const workerReceiver = {
  testWorker: async () => console.log(process.pid, 'Hello in fork'),
}

/**
 * Start test
 */
;(async function() {
  if (cluster.isMaster) {
    cluster.fork()
    const handler = new IpcMethodHandler(['test-topic'], masterReceiver)
    await handler.as<typeof workerReceiver>().testWorker()
  } else {
    const handler = new IpcMethodHandler(['test-topic'], workerReceiver)
    await handler.as<typeof masterReceiver>().testMaster()
  }
})()

ISC

1.0.17

1 year ago

1.0.16

1 year ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago