Run asynchronous commands synchronously by putting them in a separate process.
This fork adds support for running this library using an Electron executable (adds the --ms-enable-electron-run-as-node
flag).
npm install sync-rpc --save
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');
MIT