ipc-rpc

0.1.3 • Public • Published

ipc-rpc

RPC over process.send, including support for sending handles.

Both sides of the pipe can be both clients and servers.

Usage

Set up a basic server that responds to status requests with "OK!":

  functions =
    status: (msg,handle,cb) ->
      cb null"OK!"
 
  rpc = new RPC processfunctions:functionstimeout:500

On the client-side:

  rpc = new RPC server(err) =>
    if err
      # probably didn't pass in something with `.send` as server 
      throw err
 
    # ready 
 
  rpc.request "status"msg:"whatever"(err,result) =>
    # err should be null and result should be "OK!" 

Requests optionally take a handle as their third argument, before the callback.

Motivation

In StreamMachine, this library is used to facilitate handoffs of server and listener data during seamless restarts.

Example call (found here in StreamMachine):

  for source in sg._stream.sources
      if source._shouldHandoff
          do (source) =>
              @log.info "Sending StreamGroup source #{msg.key}/#{source.uuid}"
              rpc.request "group_source",
                  group:      sg.key
                  type:       source.HANDOFF_TYPE
                  opts:       format:source.opts.formatuuid:source.uuidsource_ip:source.opts.source_ip
              source.opts.sock
              (err,reply) =>
                  @log.error "Error sending group source #{msg.key}/#{source.uuid}#{err}" if err
                  af()

Readme

Keywords

Package Sidebar

Install

npm i ipc-rpc

Weekly Downloads

1

Version

0.1.3

License

none

Last publish

Collaborators

  • ewr