Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Design problem, how to call other structs method ? #405

Closed
rain2307 opened this issue Apr 25, 2023 · 0 comments
Closed

Design problem, how to call other structs method ? #405

rain2307 opened this issue Apr 25, 2023 · 0 comments

Comments

@rain2307
Copy link

rain2307 commented Apr 25, 2023

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

@rain2307 rain2307 closed this as not planned Won't fix, can't repro, duplicate, stale Oct 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant