https://github.com/laino/final-rpc
RPC for final-pm
https://github.com/laino/final-rpc
Last synced: 18 days ago
JSON representation
RPC for final-pm
- Host: GitHub
- URL: https://github.com/laino/final-rpc
- Owner: laino
- Created: 2017-12-25T08:03:34.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-10-20T13:22:36.000Z (over 7 years ago)
- Last Synced: 2025-09-02T17:57:09.097Z (9 months ago)
- Language: JavaScript
- Size: 6.84 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
FinalRPC
=======
A *dumb* (read simple) promise-aware RPC implementation with support for Pub/Sub for FinalPM.
Only RPC implementation for node right now that works with unix domain sockets out of the box
and has pub/sub.
```js
const {Client, Server} = require('final-rpc');
const path = require('path');
const server = new Server();
server.register({
add(client, a, b) {
return new Promise((resolve) => {
setTimeout(() => {
resolve(a + b);
}, 500);
});
},
subscribe(client) {
server.subscribe(client, 'news');
},
unsubscribe(client) {
server.unsubscribe(client, 'news');
}
});
setInterval(() => server.publish('news', 'hi'), 1000);
server.listen('ws+unix://' + path.resolve('rpc.sock')).then(startClient);
async function startClient() {
const client = new Client('ws+unix://'+ path.resolve('rpc.sock'));
client.pubsub.on('news', (msg) => console.log('News:', msg));
await client.invoke('subscribe');
console.log('Result:', await client.invoke('add', 5, 10));
}
```