Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: 12 days 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 (3 months ago)
- Last Synced: 2024-10-30T16:08:02.929Z (12 days 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
[![Build Status](https://img.shields.io/travis/ForbesLindesay/sync-rpc/master.svg)](https://travis-ci.org/ForbesLindesay/sync-rpc)
[![Dependency Status](https://img.shields.io/david/ForbesLindesay/sync-rpc/master.svg)](http://david-dm.org/ForbesLindesay/sync-rpc)
[![NPM version](https://img.shields.io/npm/v/sync-rpc.svg)](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