Hi, I'm trying to write a rusty_v8 based application with tokio.
And now I want to implement a setTimeout function in rust:
fn set_timeout(scope: &mut HandleScope, args: FunctionCallbackArguments, _: ReturnValue) {
let func = Local::<Function>::try_from(args.get(0)).unwrap();
let duration = Local::<Number>::try_from(args.get(1)).unwrap();
// v8::Global<v8::Function>
let global_func = Global::<Function>::new(scope, func);
tokio::spawn(async {
global_func;
// do something
});
println!("123");
}
then tokio::spawn
is underscored for:
future cannot be sent between threads safely
future created by async block is notSend
help: withinimpl std::future::Future
, the traitstd::marker::Send
is not implemented forstd::ptr::NonNull<rusty_v8::Function>
rustc
Of course, I know a v8::Global<v8::Function>
is not threads safely, but I noticed that tokio is running in single thread with rt-core
feature (which should not have a problem of thread safety?)
So, my question is as the title, am I missing something? Is there a solution?