Closed
Description
Hello,
Based on #72, Jvm cannot be sent between threads. In that case, how can I work with invoke_async
? As soon as I call await
on the future returned by invoke_async
, I get the compilation error complaining that Jvm cannot be sent between threads. How can I work around it? Thanks!
Sample error message:
the trait `Send` is not implemented for `*mut *const JNINativeInterface_`, which is required by `{async block@src/main.rs:53:134: 76:6}: Send`
Sample code snippet
#[tonic::async_trait]
impl MyApi for MyApiService {
async fn get(&self, request: Request<GetRequest>) -> Result<Response<GetResponse>, Status> {
let Ok(jvm) = Jvm::attach_thread()
else { return Err(Status::internal("attach_thread failed")) };
let Ok(my_object) = jvm.invoke_static("com.example.MyObject", "getInstance", &Vec::<InvocationArg>::new())
else { return Err(Status::internal("invoke_static failed")) };
// let args = ...
let _ = jvm.invoke_async(&my_object, "get", &vec![args]).await;
// ...
Ok(Response::new(GetResponse::default()))
}
}
Metadata
Metadata
Assignees
Labels
No labels