From 5e61e89ac154304acb6f2d7632c88cc010888d53 Mon Sep 17 00:00:00 2001 From: Arsen Musayelyan Date: Fri, 3 Jun 2022 17:59:58 -0700 Subject: [PATCH] Add LRPCClient.getObject() --- client/web/lrpc.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/client/web/lrpc.rb b/client/web/lrpc.rb index 05eadca..51fcc30 100644 --- a/client/web/lrpc.rb +++ b/client/web/lrpc.rb @@ -92,6 +92,27 @@ class LRPCClient @conn.send(data.buffer) end end + + # getClient returns an object containing functions + # corresponding to registered functions on the given + # receiver. It uses the lrpc.Introspect() endpoint + # to achieve this. + def getObject(rcvr) + return Promise.new do |resolve| + # Introspect methods on given receiver + self.callMethod("lrpc", "Introspect", rcvr).then do |methodDesc| + # Create output object + out = {} + # For each method in description array + methodDesc.each do |method| + # Create and assign new function to call current method + out[method.Name] = proc { |arg| return self.callMethod(rcvr, method.Name, arg) } + end + # Resolve promise with output promise + resolve(out) + end + end + end end # LRPCChannel represents a channel used for lrpc.