1.3.6-beta.2 • Published 7 months ago

@carriyo/sync-rpc v1.3.6-beta.2

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

sync-rpc

Run asynchronous commands synchronously by putting them in a separate process

Build Status Dependency Status NPM version

Installation

npm install @carriyo/sync-rpc --save

Usage

worker.js

function init(connection) {
  // you can setup any connections you need here
  return function (message) {
    // Note how even though we return a promise, the resulting rpc client will be synchronous
    return Promise.resolve('sent ' + message + ' to ' + connection);
  }
}
module.exports = init;
const assert = require('assert');
const rpc = require('sync-rpc');

const client = rpc(__dirname + '/../test-worker.js', 'My Server');

const result = client('My Message');

assert(result === 'sent My Message to My Server');

// For local debugging, closing child process maybe needed for node.js debugger
// to detach from child process
// Also for unit tests, some test reporter don't exit until stdin is closed.
rpc.cleanup();

License

MIT

1.3.6-beta.2

7 months ago

1.3.6-beta.1

7 months ago