import { RPCSocket, RPCServer } from "./Index" // TL;DR const echo = (text: string) => {throw new Error("XD")} const add = (a: number, b: number) : number => a + b const getAsync = async () : Promise<{topic: string, message:string}>=> await new Promise((res, _) => { setTimeout(() => { res({ topic: "Hey!!", message: "Hello World Async!" }) }, 250) }) const getCallback = (cbb: Function) : string => { setTimeout(() => { try{ cbb({ topic: "Hey!!", message: "Hello World Callback!" }) }catch(e){ console.log(String(e)) } }, 250) return "Please wait for a callback :)" } new RPCServer(20000, [{ name: 'MyRPCGroup1', exportRPCs: () => [ echo, add, getAsync, { name: 'getCallback', hook: getCallback, onClose: (response, rpc) => { }, onCallback: (...callbackArgs) => { } } ] }]) new RPCSocket(20000, 'localhost').connect() .then(async sock => { try{ const val = await sock.call('ABCD', 12345) console.log("VAL",val); }catch(e){ console.log("RPC error "+e) } }).catch(e => console.log("connect err: "+e))