-
Notifications
You must be signed in to change notification settings - Fork 173
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
rpc module: register_async_method
only allows Copy
closures
#947
Comments
hey @Code0x2 Can you give an example what you are trying to do? I think it should work if you clone the sender and move into closure by |
Yeah, alright seems like we need to change the bound to However, you could move that Example with proc macros: use std::net::SocketAddr;
use futures::SinkExt;
use jsonrpsee::core::{async_trait, Error};
use jsonrpsee::proc_macros::rpc;
use jsonrpsee::server::ServerBuilder;
#[rpc(server, client, namespace = "state")]
pub trait Rpc {
/// Async method call example.
#[method(name = "getKeys")]
async fn say_hello(&self) -> Result<u32, Error>;
}
pub struct RpcServerImpl {
sender: futures::channel::mpsc::UnboundedSender<()>,
}
#[async_trait]
impl RpcServer for RpcServerImpl {
async fn say_hello(&self) -> Result<u32, Error> {
self.sender.clone().send(()).await.unwrap();
Ok(11)
}
}
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let _ = run_server().await?;
loop {}
}
async fn run_server() -> anyhow::Result<SocketAddr> {
let server = ServerBuilder::default().build("127.0.0.1:0").await?;
let (tx, rx) = futures::channel::mpsc::unbounded();
let addr = server.local_addr()?;
let handle = server.start(RpcServer::into_rpc(RpcServerImpl { sender: tx }))?;
tokio::spawn(handle.stopped());
Ok(addr)
}
|
register_async_method
only allows Copy
closures
Great this fixes the problem. Thanks for the quick fix and merge! |
Im creating a method that will take the values, send it into a channel, and then await its response, by using register_async_method. However, it doesnt let me utilize the mpsc::UnboundedSender because it doesnt implement copy, which is a bound on the register_async_method callback. Is there some other way I can go about sending values down a channel?
I tried register_method, but i can send that message into a channel just fine. But the problem is i want to await its response from the other end of the channel and i dont want to use a blocking recv method to do so.
The text was updated successfully, but these errors were encountered: