@@ -1030,14 +1030,41 @@ pub fn memo(input: TokenStream) -> TokenStream {
1030
1030
memo:: memo_impl ( input)
1031
1031
}
1032
1032
1033
- /// The `#[lazy]` macro marks an `async` function as a function that can be lazy-loaded from a
1034
- /// separate (WebAssembly) binary.
1033
+ /// The `#[lazy]` macro indicates that a function can be lazy-loaded from a separate WebAssembly (WASM) binary.
1035
1034
///
1036
1035
/// The first time the function is called, calling the function will first load that other binary,
1037
- /// then call the function. On subsequent call it will be called immediately, but still return
1036
+ /// then call the function. On subsequent calls it will be called immediately, but still return
1038
1037
/// asynchronously to maintain the same API.
1039
1038
///
1040
- /// All parameters and output types should be concrete types, with no generics.
1039
+ /// `#[lazy]` can be used to annotate synchronous or `async` functions. In both cases, the final function will be
1040
+ /// `async` and must be called as such.
1041
+ ///
1042
+ /// All parameters and output types should be concrete types, with no generics or `impl Trait` types.
1043
+ ///
1044
+ /// This should be used in tandem with a suitable build process, such as `cargo leptos --split`.
1045
+ ///
1046
+ /// ```rust
1047
+ /// # use leptos_macro::lazy;
1048
+ ///
1049
+ /// #[lazy]
1050
+ /// fn lazy_synchronous_function() -> String {
1051
+ /// "Hello, lazy world!".to_string()
1052
+ /// }
1053
+ ///
1054
+ /// #[lazy]
1055
+ /// async fn lazy_async_function() -> String {
1056
+ /// /* do something that requires async work */
1057
+ /// "Hello, lazy async world!".to_string()
1058
+ /// }
1059
+ ///
1060
+ /// async fn use_lazy_functions() {
1061
+ /// // synchronous function has been converted to async
1062
+ /// let value1 = lazy_synchronous_function().await;
1063
+ ///
1064
+ /// // async function is still async
1065
+ /// let value1 = lazy_async_function().await;
1066
+ /// }
1067
+ /// ```
1041
1068
#[ proc_macro_attribute]
1042
1069
#[ proc_macro_error]
1043
1070
pub fn lazy ( args : proc_macro:: TokenStream , s : TokenStream ) -> TokenStream {
0 commit comments