Tarpc 如何调用外部结构的方法?

问题描述 投票:0回答:0

Github 问题https://github.com/google/tarpc/issues/405

演示: 我做了一个简单的演示https://github.com/divflex/demo-rpc

问题:

HelloServer
基本上是
SingletonInstance
的代理,因此
say_hi
方法需要在
SingletonInstance
上调用相同的方法。
SingletonInstance::say_hi
的正确称呼是什么?

我的想法: 通过消息传递 https://github.com/divflex/demo-rpc/blob/ffe9dd49c0d2bcdf65771b00397e64473d7debfd/server/src/server.rs#L24

我在

tx
上创建了一个
tokio::sync::mpsc
(
HelloServer
)属性,所以实例可以使用
self.tx.send()
SingletonInstance
进行通信。但是HelloServer还需要一个接收器来获取结果。这似乎太复杂了。

第二题: 这部分代码可以吗? https://github.com/divflex/demo-rpc/blob/ffe9dd49c0d2bcdf65771b00397e64473d7debfd/server/src/server.rs#L33

rust rpc
© www.soinside.com 2019 - 2024. All rights reserved.