pub struct Resource<T>where
T: 'static,{ /* private fields */ }Expand description
Declarative async data loading (§4.5): a TRACKED source whose value feeds an async
fetcher; the result lands in a Signal<Load<T>>. The source re-runs when its tracked
reads change; an unchanged source value refetches nothing, Resource::refetch always
does. Latest wins: a source change supersedes the in-flight fetch (aborting its task —
dropping any FetchFuture inside cancels the platform request) and a stale completion
writes nothing. Scope disposal aborts the in-flight fetch the same way.
let stations = Resource::new(
move || region.get(), // tracked: refetch on change
|region| async move { fetch_stations(region).await },
);
when(move || stations.ready(), move || station_list(stations));Implementations§
Source§impl<T> Resource<T>where
T: 'static,
impl<T> Resource<T>where
T: 'static,
Sourcepub fn new<S, Fut, E>(
source: impl Fn() -> S + 'static,
fetcher: impl Fn(S) -> Fut + 'static,
) -> Resource<T>
pub fn new<S, Fut, E>( source: impl Fn() -> S + 'static, fetcher: impl Fn(S) -> Fut + 'static, ) -> Resource<T>
Start loading: source runs tracked (its signal reads become dependencies) and its
value moves into fetcher’s future, which runs on the main-loop executor via the
installed spawner — so no Send bound anywhere, and the future may read/write signals
after its awaits. Infallible fetchers use E = std::convert::Infallible.
Sourcepub fn signal(self) -> Signal<Load<T>>
pub fn signal(self) -> Signal<Load<T>>
The underlying state signal (tracked reads, when(move || …) guards, each sources).
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Resource<T>
impl<T> !RefUnwindSafe for Resource<T>
impl<T> !Send for Resource<T>
impl<T> !Sync for Resource<T>
impl<T> Unpin for Resource<T>
impl<T> UnsafeUnpin for Resource<T>
impl<T> !UnwindSafe for Resource<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more