1.1.0 • Published 6 months ago

@primafuture/remote-async-call v1.1.0

Weekly downloads
-
License
ISC
Repository
-
Last release
6 months ago

@primafuture/remote-async-call

Installation

npm install @primafuture/remote-async-call

Package can be used directly in the browser without the use of package managers/bundlers as well: UMD version from unpkg.com.

Usage

import rac from '@primafuture/remote-async-call';

// create connection
const ws = new websocket.WebSocket("ws://...");
const racProxy = new rac.RACProxy(new rac.WebsocketCommunicationConnection(ws));

RPC model

// register method
racProxy.register('sum', ([a, b]:[number, number]) => {
	const res = a + b;
	return res;
});

// call method
let result = await racProxy.call('sum', [2, 3]);
console.log(result);

Pub/Sub model

// subscribe event
racProxy.subscribe('event', (args) => {
	console.log('on event', args);
});

// publish event
await racProxy.publish('event', [1, 2, 3]);
1.1.0

6 months ago

1.0.3

6 months ago

1.0.2

6 months ago

1.0.1

6 months ago

1.0.0

6 months ago