From 61494ce92eabcf1b04c87eada295859ef69d3124 Mon Sep 17 00:00:00 2001 From: Niklas Adolfsson Date: Wed, 23 Nov 2022 11:07:35 +0100 Subject: [PATCH] fix(rpc module): make async closures Clone --- core/src/server/rpc_module.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/core/src/server/rpc_module.rs b/core/src/server/rpc_module.rs index 2027d3e85e..29e9fcd5a5 100644 --- a/core/src/server/rpc_module.rs +++ b/core/src/server/rpc_module.rs @@ -577,13 +577,15 @@ impl RpcModule { where R: Serialize + Send + Sync + 'static, Fut: Future> + Send, - Fun: (Fn(Params<'static>, Arc) -> Fut) + Copy + Send + Sync + 'static, + Fun: (Fn(Params<'static>, Arc) -> Fut) + Clone + Send + Sync + 'static, { let ctx = self.ctx.clone(); let callback = self.methods.verify_and_insert( method_name, MethodCallback::new_async(Arc::new(move |id, params, _, max_response_size, claimed| { let ctx = ctx.clone(); + let callback = callback.clone(); + let future = async move { let result = match callback(params, ctx).await { Ok(res) => MethodResponse::response(id, res, max_response_size), @@ -612,13 +614,14 @@ impl RpcModule { where Context: Send + Sync + 'static, R: Serialize, - F: Fn(Params, Arc) -> Result + Copy + Send + Sync + 'static, + F: Fn(Params, Arc) -> Result + Clone + Send + Sync + 'static, { let ctx = self.ctx.clone(); let callback = self.methods.verify_and_insert( method_name, MethodCallback::new_async(Arc::new(move |id, params, _, max_response_size, claimed| { let ctx = ctx.clone(); + let callback = callback.clone(); tokio::task::spawn_blocking(move || { let result = match callback(params, ctx) {