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
//! # Async
//!
//! Freya has its own async runtime, so tasks can update reactive state directly.
//! These are the async primitives, each one documents when to use it and how in
//! its own definition.
//!
//! ## Tasks
//!
//! - [`spawn`](crate::prelude::spawn) runs a future attached to the current
//! component scope, it gets cancelled when that component unmounts. Use it for
//! async work owned by a component.
//! - [`spawn_forever`](crate::prelude::spawn_forever) runs a future attached to
//! the root scope, it keeps running until the app exits. Use it for app-wide
//! background work that must outlive the component that started it.
//!
//! Both return a [`TaskHandle`](crate::prelude::TaskHandle) to cancel the task
//! manually. [`.owned()`](crate::prelude::TaskHandle::owned) upgrades it to an
//! [`OwnedTaskHandle`](crate::prelude::OwnedTaskHandle) that cancels the task
//! when its last clone is dropped.
//!
//! ## Hooks
//!
//! - [`use_future`](crate::prelude::use_future) wraps `spawn` and exposes the
//! progress of the future as reactive state through a
//! [`FutureTask`](crate::prelude::FutureTask), so you can render the
//! [`Pending`](crate::prelude::FutureState::Pending),
//! [`Loading`](crate::prelude::FutureState::Loading) and
//! [`Fulfilled`](crate::prelude::FutureState::Fulfilled) cases without
//! managing the task by hand. Its callback is reactive, any state read inside
//! of it (outside the async block) restarts the future when it changes.
//!
//! ## See also
//!
//! - [Tokio Integration](crate::_docs::tokio_integration) to use crates that
//! depend on Tokio.
//! - [State Management](crate::_docs::state_management) for caching and syncing
//! async data with Freya Query.