1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-03 12:58:54 -05:00

docs: Improve mod_evaluate documentation (#14827)

This commit is contained in:
Christian Dürr 2022-06-20 12:40:57 +00:00 committed by GitHub
parent 4cbb2567b5
commit 94d369ebc6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 9 deletions

View file

@ -28,9 +28,9 @@ fn main() -> Result<(), Error> {
let future = async move {
let mod_id = js_runtime.load_main_module(&main_module, None).await?;
let _ = js_runtime.mod_evaluate(mod_id);
let result = js_runtime.mod_evaluate(mod_id);
js_runtime.run_event_loop(false).await?;
Ok(())
result.await?
};
runtime.block_on(future)
}

View file

@ -109,9 +109,9 @@ fn main() -> Result<(), Error> {
let future = async move {
let mod_id = js_runtime.load_main_module(&main_module, None).await?;
let _ = js_runtime.mod_evaluate(mod_id);
let result = js_runtime.mod_evaluate(mod_id);
js_runtime.run_event_loop(false).await?;
Ok(())
result.await?
};
tokio::runtime::Builder::new_current_thread()

View file

@ -1190,10 +1190,11 @@ impl JsRuntime {
/// Evaluates an already instantiated ES module.
///
/// Returns a receiver handle that resolves when module promise resolves.
/// Implementors must manually call `run_event_loop()` to drive module
/// evaluation future.
/// Implementors must manually call [`JsRuntime::run_event_loop`] to drive
/// module evaluation future.
///
/// `Error` can usually be downcast to `JsError`.
/// `Error` can usually be downcast to `JsError` and should be awaited and
/// checked after [`JsRuntime::run_event_loop`] completion.
///
/// This function panics if module has not been instantiated.
pub fn mod_evaluate(
@ -1550,7 +1551,7 @@ impl JsRuntime {
/// The module will be marked as "main", and because of that
/// "import.meta.main" will return true when checked inside that module.
///
/// User must call `JsRuntime::mod_evaluate` with returned `ModuleId`
/// User must call [`JsRuntime::mod_evaluate`] with returned `ModuleId`
/// manually after load is finished.
pub async fn load_main_module(
&mut self,
@ -1609,7 +1610,7 @@ impl JsRuntime {
/// This method is meant to be used when loading some utility code that
/// might be later imported by the main module (ie. an entry point module).
///
/// User must call `JsRuntime::mod_evaluate` with returned `ModuleId`
/// User must call [`JsRuntime::mod_evaluate`] with returned `ModuleId`
/// manually after load is finished.
pub async fn load_side_module(
&mut self,