1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use crate::;
/// Streams child content in, showing a fallback until it is ready.
///
/// The fallback renders with the surrounding document, so a slow child does
/// not hold the rest of the page back. Once the child content is ready, it
/// replaces the fallback in place.
///
/// Errors from the child are not caught; wrap the child in an
/// [`error_boundary`](super::error_boundary) to handle them.
///
/// ```rust
/// use topcoat::{
/// Result,
/// view::{View, component, suspense, view},
/// };
///
/// #[component]
/// async fn quote() -> Result<impl View> {
/// let quote = fetch_quote().await;
/// Ok(view! { <blockquote>(quote)</blockquote> })
/// }
/// # async fn fetch_quote() -> &'static str { "..." }
///
/// #[component]
/// async fn page() -> Result<impl View> {
/// Ok(view! {
/// suspense(
/// fallback: view! { <p>"Loading..."</p> },
/// quote()
/// )
/// })
/// }
/// ```
///
/// The component is a [`live!`] region that emits the fallback and then the
/// child content. Use [`live!`] and [`emit!`] directly for cases it does not
/// cover, like narrating a long-running task through a sequence of emissions.
///
/// [`live!`]: macro@crate::view::live
/// [`emit!`]: macro@crate::view::emit
pub async