https://github.com/ForbesLindesay/sync-rpc
Run asynchronous commands synchronously by putting them in a separate process
https://github.com/ForbesLindesay/sync-rpc
Last synced: 4 months ago
JSON representation
Run asynchronous commands synchronously by putting them in a separate process
- Host: GitHub
- URL: https://github.com/ForbesLindesay/sync-rpc
- Owner: ForbesLindesay
- License: mit
- Created: 2017-06-06T11:25:12.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2024-08-16T09:44:40.000Z (6 months ago)
- Last Synced: 2024-10-30T16:08:02.929Z (4 months ago)
- Language: JavaScript
- Size: 8.46 MB
- Stars: 76
- Watchers: 3
- Forks: 11
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Changelog: HISTORY.md
- License: LICENSE.md
- Security: SECURITY.md
Awesome Lists containing this project
README
# sync-rpc
Run asynchronous commands synchronously by putting them in a separate process
[](https://travis-ci.org/ForbesLindesay/sync-rpc)
[](http://david-dm.org/ForbesLindesay/sync-rpc)
[](https://www.npmjs.org/package/sync-rpc)## Installation
```
npm install sync-rpc --save
```## Usage
### worker.js
```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;
``````js
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');
```## License
MIT