Design problem, how to call other structs method ?
rain2307 opened this issue · 0 comments
The demo:
I made a simple demo https://github.com/divflex/demo-rpc
stackoverflow
https://stackoverflow.com/questions/76097231/tarpc-how-to-call-outer-structs-method
Question:
The HelloServer
is basiclly a proxy for the SingletonInstance
, so the say_hi
method need to call the same method on SingletonInstance
.
What's the proper way to call SingletonInstance::say_hi
?
My idea:
Through messaging
https://github.com/divflex/demo-rpc/blob/ffe9dd49c0d2bcdf65771b00397e64473d7debfd/server/src/server.rs#L24
I created a tx
(tokio::sync::mpsc
) property on HelloServer
, so the instance can use self.tx.send()
to communicate with SingletonInstance
.But HelloServer
also need a receiver to get results. This seems too complicated.
The second question
Is this part of code ok?
https://github.com/divflex/demo-rpc/blob/ffe9dd49c0d2bcdf65771b00397e64473d7debfd/server/src/server.rs#L33