Compare commits

...

2 Commits

Author SHA1 Message Date
Elara 5e61e89ac1 Add LRPCClient.getObject() 2022-06-03 17:59:58 -07:00
Elara 205e0b71e4 Actually skip LRPCChannel.close() this time 2022-06-03 14:36:34 -07:00
1 changed files with 22 additions and 0 deletions

View File

@ -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.
@ -145,6 +166,7 @@ class LRPCChannel
# close closes the channel. This should not be called by the
# consumer of the channel. Use done() instead.
def close()
return if @closed
fn = @onClose
fn()
@closed = true