From ac8bd2da78b121fd66875e792103ba6757ee3f60 Mon Sep 17 00:00:00 2001 From: mx Date: Sun, 8 Sep 2024 03:19:17 +1200 Subject: [PATCH] Guide: added and async fn call example with f64 (#4097) --- guide/src/reference/js-promises-and-rust-futures.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/guide/src/reference/js-promises-and-rust-futures.md b/guide/src/reference/js-promises-and-rust-futures.md index 1598a1e83ba..89aea0a1e82 100644 --- a/guide/src/reference/js-promises-and-rust-futures.md +++ b/guide/src/reference/js-promises-and-rust-futures.md @@ -32,9 +32,13 @@ must be `JsValue` or no return at all: ```rust #[wasm_bindgen] extern "C" { - async fn async_func_1() -> JsValue; + async fn async_func_1_ret_number() -> JsValue; async fn async_func_2(); } + +async fn get_from_js() -> f64 { + async_func_1_ret_number().await.as_f64().unwrap_or(0.0) +} ``` The `async` can be combined with the `catch` attribute to manage errors from the