ataraxia-services
Services with RPC and events for Ataraxia.
This project provides a service layer on top of a Ataraxia network and allows
nodes to easily register services and to call methods and receive events on
services on other nodes.
Usage
npm install ataraxia-services
const Services = require('ataraxia-services');
const net = ...
const services = new Services(net);
services.on('available', service => console.log(service.id, 'is now available'));
services.on('unavailable', service => console.log(service.id, 'is no longer available'));
const handle = services.register('service-id', {
hello() {
return 'Hello world';
}
});
handle.emitEvent('hello', { data: 'goes-here' });
const service = services.get('service-id');
service.hello()
.then(result => console.log('service said', result))
.catch(handleErrorCorrectlyHere);
service.on('hello', data => console.log('got', data));
Creat