rpc4ts
v1.0.4
Published
an abstract rpc for typescript
Downloads
3
Readme
RPC for Typescript
an abstract rpc for typescript
Install
yarn add rpc4ts
ornpm i rpc4ts -S
Usage
import {createCallee, createCaller, RPCImplBase} from "rpc4ts";
import {BucketRPCConnector} from "rpc4ts"
const bucketCallee = []
const bucketCaller = []
/**
* Callee side
*/
class TestRPCImpl extends RPCImplBase {
add(a, b) {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve(a + b)
}, 1000)
})
}
}
createCallee(new TestRPCImpl(), new BucketRPCConnector(bucketCallee, bucketCaller))
/**
* Caller side
*/
interface TestRpc {
add(a: number, b: number): Promise<number>
}
const caller = createCaller<TestRpc>(new BucketRPCConnector(bucketCaller, bucketCallee))
caller.add(1, 2).then(
sum => {
console.log('sum:', sum)
},
e => {
console.log('err:', e)
}
)