D
Deno

help

Return results from execute_main_module

Kk-xo9/22/2023
I currently have this function to run some execute some js
pub async fn run(&self, path_to_main_module: &Path) -> Result<()> {
let main_module = ModuleSpecifier::from_file_path(path_to_main_module).map_err(|_| {
anyhow::anyhow!(
"Failed to create module specifier from path: {:?}",
path_to_main_module
)
})?;

let mut main_worker = deno_runtime::worker::MainWorker::bootstrap_from_options(
main_module.clone(),
PermissionsContainer::new(Permissions {
write: UnaryPermission::default(),
read: UnaryPermission::default(),
ffi: UnaryPermission::default(),
env: UnaryPermission::default(),
..Permissions::allow_all()
}),
Default::default(),
);

main_worker.execute_main_module(&main_module).await?;
Ok(())
}
pub async fn run(&self, path_to_main_module: &Path) -> Result<()> {
let main_module = ModuleSpecifier::from_file_path(path_to_main_module).map_err(|_| {
anyhow::anyhow!(
"Failed to create module specifier from path: {:?}",
path_to_main_module
)
})?;

let mut main_worker = deno_runtime::worker::MainWorker::bootstrap_from_options(
main_module.clone(),
PermissionsContainer::new(Permissions {
write: UnaryPermission::default(),
read: UnaryPermission::default(),
ffi: UnaryPermission::default(),
env: UnaryPermission::default(),
..Permissions::allow_all()
}),
Default::default(),
);

main_worker.execute_main_module(&main_module).await?;
Ok(())
}
I was wondering how I could modify this to return the result of the executed javascript?
ABTAndreu Botella (they/them)9/22/2023
JS modules don't have results, unless you mean the module namespace object
Kk-xo9/22/2023
Not quite sure what you mean, but overall goal is to sort maintain similar flow you see above, and then be able to return the result to the Rust program, is that something that possible? I saw this issue --> https://github.com/denoland/deno/issues/11105, but when I tried to run certain js programs that used things like 'fetch' with execute_script nothing occurred, so opted for execute_main_module. But yeah if you have any advice for overall the best way to go about this, would really appreciate it!
GitHub
Issues · denoland/deno
A modern runtime for JavaScript and TypeScript. Contribute to denoland/deno development by creating an account on GitHub.
ABTAndreu Botella (they/them)9/22/2023
you'd have to use run_event_loop but IIRC you'd also need to use it for execute_main_module if execute_script returns a promise, you can run the event loop and wait until it resolves with JsRuntime::resolve_value
Kk-xo9/22/2023
I see, do you know if there are any examples / docs that I could take a look at / build off of?

Looking for more? Join the community!

Recommended Posts
Fresh Blog + Website Thingshttps://vuepress-theme-yuu.netlify.app/, what is the closest thing to that which can be run on FreshDetermine subcommandIf I run `deno test` from the command line, how can I determine that `test` is the subcommand being setting a cookie for import requestsis there a way to modify request headers or set cookies for the GET requests that deno makes when reHow to run tailwindcss cli with deno task?I would like to be able to run the tailwindcss cli tool to watch and build stylesheets as per their Deno DeployIs it possible to use only cronjobs on deno deploy?Deno cannot import mainfile by reading from package.jsondeno 1.36.0 (release, x86_64-unknown-linux-gnu) v8 11.6.189.12 typescript 5.1.6Deno LSP in a Web WorkerHas anyone come across the lsp running in a web worker? I have an online editor (Monaco) that peopleHow do you get a Deno Jupyter notebook to recognize Deno and other types in vscode?See attached screenshotModule not found when running deno runSomething weird has started happening. When I run `deno run src/main.ts` it seems as if Deno is tryesm_entry_point / extension macro; ReferenceErrorHow do I use esm_entry_point properly? I defined my extension as: ```rust extension!( ext_name,remoteAddr returning localhost on Deno DeployI saw this thread (https://discord.com/channels/684898665143206084/1055631150787334184) about gettinDeno-native Nuxt.js?The recent [The State of Web Frameworks on Deno](https://deno.com/blog/web-frameworks-on-deno) blogDeno support Fleet IDE?Hello, can the deno plug-in be used on the Fleet editor of JetBrains IDEs? Thank you.Async execution contextIs there any way I can create a global that is unique to an async operation? I would like to use tha