I'm trying to convert RPC calls to an Async stream, but don't know how to do so.
struct Args1;
struct Args2;
enum Msg {
Args1(Args1),
Args2(Args2)
}
struct Service {
sender: Sender<Msg>
}
#[async_trait::async_trait]
impl RpcService for Service {
async fn rpc1(&self, args: Args1) -> MyResult<Reply1> {
self.sender.send(Msg::Args1(args));
todo!() // how to return
}
async fn rpc2(&self, args: Args2) -> MyResult<Reply2> {
self.sender.send(Msg::Args2(args));
todo!() // how to return
}
}
fn main() {
// ...
loop {
let message = receiver.receive().await;
let reply = handle(message); // how to return this reply?
}
}
In the example, there are two rpc methods. The sender
and receiver
is part of an async channel.
I would like to convert these rpcs calls (rpc1
and rpc2
) to an Async stream, so that I can use the "reactive pattern" to handle them.
But here is the problem, How to retrieve the result of the handle
fucntion and return it in the method rpc1
and rpc2
.