calling a javascript function and waiting for the promise with `rusty_v8`
result.is_promise
is true
promise state is Pending
scope.has_pending_background_tasks()
is false
which confuses me. Isnt this supposed to be true if there are unresolved promises?13 Replies
v8::Isolate::has_pending_background_tasks
is about V8-managed asynchronous tasks, like GC or wasm compilation
if you're using deno_core or deno_runtime, the promise is managed by the deno_core event loopand you could wait until a promise resolves with
JsRuntime::resolve_value
(https://docs.rs/deno_core/0.189.0/deno_core/struct.JsRuntime.html#method.resolve_value)JsRuntime in deno_core - Rust
A single execution context of JavaScript. Corresponds roughly to the “Web Worker” concept in the DOM. A JsRuntime is a Future that can be used with an event loop (Tokio, async_std). The JsRuntime future completes when there is an error or when all pending ops have completed.
if you're not using deno_core, you'd have to delegate to whichever event loop handles the promise
i am using
rusty_v8
. But i am unsure how to handle the event loop here. is it possible to get the value synchronously? or do you have any examples which i can refer to?
i have the result: Local<Value>
which is a promise (result.is_promise
is true).
what i am trying to do is
let value = get_inner_value_synchronously(result)
. is this possible?no
something like an "await" version in rust
in the JS code you posted in the rusty_v8 issue, it wasn't awaiting on anything, right?
in that case, I would have expected
v8::Function::call
to run microtasks, after which the promise should not have been pending anymore
it's odd that it's still pendingit was
yea!, thats what is puzzling me.
promise.state() is Pending
, i tried pumping the loop as well in a while loop
yeah, that will not work
this
main
function is being called from rust
thats how i got the result promise which i am expecting will resolve to "helloworld"
if i make the above js function sync (just removing the async
) then the whole thing works, i get the result string "helloworld" out. so the function call works.
this result
above is giving result.is_promise()
true. which i expect it to. But i do not understand why it is always in pending
scope.perform_microtask_checkpoint();
i tried running this as well.I'm not sure
GitHub
how to synchronously wait for a promise value · Issue #1259 · denol...
Hi, I am trying to call a javascript function from rust using v8 isolates. Something like this. let isolate = &mut v8::Isolate::new(v8::CreateParams::default()); let handle_scope = &mut v8:...
asked here, got the answer!
thanks a lot!