D
Deno

help

calling a javascript function and waiting for the promise with `rusty_v8`

AAV66/30/2023
let result = function.call(scope, recv, &[]).expect("couldnt run");
/*i got this result which is a promise. now how do i get the value of the promise

let value = ??
*/
let result = function.call(scope, recv, &[]).expect("couldnt run");
/*i got this result which is a promise. now how do i get the value of the promise

let value = ??
*/
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?
ABTAndreu Botella (they/them)6/30/2023
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 loop
ABTAndreu Botella (they/them)6/30/2023
and 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.
ABTAndreu Botella (they/them)6/30/2023
if you're not using deno_core, you'd have to delegate to whichever event loop handles the promise
AAV66/30/2023
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?
ABTAndreu Botella (they/them)6/30/2023
no
AAV66/30/2023
something like an "await" version in rust
ABTAndreu Botella (they/them)6/30/2023
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 pending
AAV66/30/2023
it was
async function main() {
return "helloworld"
}
async function main() {
return "helloworld"
}
yea!, thats what is puzzling me. promise.state() is Pending, i tried pumping the loop as well in a while loop
while v8::Platform::pump_message_loop(&v8::V8::get_current_platform(), scope, false) {
// do nothing
}
while v8::Platform::pump_message_loop(&v8::V8::get_current_platform(), scope, false) {
// do nothing
}
ABTAndreu Botella (they/them)6/30/2023
yeah, that will not work
AAV66/30/2023
this main function is being called from rust
let result = function.call(scope, recv, &[]).expect("couldnt run");
let result = function.call(scope, recv, &[]).expect("couldnt run");
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.
ABTAndreu Botella (they/them)6/30/2023
I'm not sure
AAV66/30/2023
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:...
AAV66/30/2023
asked here, got the answer! thanks a lot!

Looking for more? Join the community!

Recommended Posts
Deno KV: subtract with `sum` operation?If I do `.sum([key], 1n)` the value is increased by 1. How can I decrease it? I tried `.sum([key], How to use declarations from `vite/client`?There are declarations: https://esm.sh/v126/vite@4.3.9/client.d.ts According to documentation, I neegetting errno with ffiI am using ffi to call `execv` and need to get the value of `errno` for failures, but can’t see how Purging Kv keysI have a logger which write logs to a kv store with dual keys, something like ```ts kv.set(["logs_bWhat is the right way to bundle native modules?If I'm not able to import a native module with the built-in "import" keyword, what is the ideal way HandleScope in async opIs there a way to get v8::HandleScope inside async op if I add it as ``` scope: &mut v8::HandleScopDeno LSP randomly breaks until a restart (unable to send result to client)This wasnt an issue until recently. In vscode randomly the lsp stops working. Trying to use the autoIs anyone working on LLMs for Deno so I don't have to learn it in disgusting Python?I'm coming to terms with the reality of having to learn this technology but not on Python.. I mean..Permission denied (os error 13)Please help me, I'm desparate. It doesn't print anything else.Is there a rich text (wysiwyg) editor for deno fresh ?I'm working on a blog, and i need a rich text editor for articles.deno_core usageAre there any repos using deno_core in their code + how would I enable the unstable features and URLError reading `allocUnsafe` using npm:icsHello there, I try to use npm:ics in my project and in some runs it works, in others it doesn't (whiUsing discord.js in Deno?Apparently Deno supports discord.js now. Awesome. But now I can't make it work. According to debug Type alias with inherited type parameter constraintsIs there any way to do this? I want SVLTN to just be a short-name alias for SomeVeryLongTypeName, anFresh: global stateIs it possible to have a global state that can be accessed from anywhere? Currently I'm passing the Run Deno on Linux without /proc mountedI have a few automatic scripts using deno to run stuff, and wanted to migrate them to another MachinReasons to choose Node.jsI've been tasked to write a list of pros/cons of Deno in comparison to Node.js. I am quite honestly Reejs not working on Deno v1.34```js deno run -A npm:reejs [INFO] Saving important data... [TIP] If the error indeno.land published the same GitHub tag twicehttps://deno.land/x/smee_client_unofficial@v1.2.3 Could someone please just delete the older one?Uncaught (in promise) eof for websocket/root/.pm2/logs/twitter-follow-checker-error.log last 15 lines: 0|twitter_ |