JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 9
  • Score
    100M100P100Q47749F

RPC over process.send

Package Exports

  • ipc-rpc

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ipc-rpc) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme


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 process, functions:functions, timeout: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.format, uuid:source.uuid, source_ip:source.opts.source_ip
              , source.opts.sock
              , (err,reply) =>
                  @log.error "Error sending group source #{msg.key}/#{source.uuid}: #{err}" if err
                  af()