pub struct ArcAsyncDerived<T> { /* private fields */ }Expand description
A reactive value that is derived by running an asynchronous computation in response to changes in its sources.
When one of its dependencies changes, this will re-run its async computation, then notify other values that depend on it that it has changed.
This is a reference-counted type, which is Clone but not Copy.
For arena-allocated Copy memos, use AsyncDerived.
§Examples
let signal1 = RwSignal::new(0);
let signal2 = RwSignal::new(0);
let derived = ArcAsyncDerived::new(move || async move {
// reactive values can be tracked anywhere in the `async` block
let value1 = signal1.get();
tokio::time::sleep(std::time::Duration::from_millis(25)).await;
let value2 = signal2.get();
value1 + value2
});
// the value can be accessed synchronously as `Option<T>`
assert_eq!(derived.get(), None);
// we can also .await the value, i.e., convert it into a Future
assert_eq!(derived.clone().await, 0);
assert_eq!(derived.get(), Some(0));
signal1.set(1);
// while the new value is still pending, the signal holds the old value
tokio::time::sleep(std::time::Duration::from_millis(5)).await;
assert_eq!(derived.get(), Some(0));
// setting multiple dependencies will hold until the latest change is ready
signal2.set(1);
assert_eq!(derived.await, 2);§Core Trait Implementations
.get()clones the current value as anOption<T>. If you call it within an effect, it will cause that effect to subscribe to the memo, and to re-run whenever the value of the memo changes..get_untracked()clones the value of without reactively tracking it.
.read()returns a guard that allows accessing the value by reference. If you call it within an effect, it will cause that effect to subscribe to the memo, and to re-run whenever the value changes..read_untracked()gives access to the current value without reactively tracking it.
.with()allows you to reactively access the value without cloning by applying a callback function..with_untracked()allows you to access the value by applying a callback function without reactively tracking it.
IntoFutureallows you to create aFuturethat resolves when this resource is done loading.
Implementations§
Source§impl<T> ArcAsyncDerived<T>where
T: 'static,
impl<T> ArcAsyncDerived<T>where
T: 'static,
Sourcepub fn new<Fut>(
fun: impl Fn() -> Fut + Send + Sync + 'static,
) -> ArcAsyncDerived<T>
pub fn new<Fut>( fun: impl Fn() -> Fut + Send + Sync + 'static, ) -> ArcAsyncDerived<T>
Creates a new async derived computation.
This runs eagerly: i.e., calls fun once when created and immediately spawns the Future
as a new task.
Sourcepub fn new_with_initial<Fut>(
initial_value: Option<T>,
fun: impl Fn() -> Fut + Send + Sync + 'static,
) -> ArcAsyncDerived<T>
pub fn new_with_initial<Fut>( initial_value: Option<T>, fun: impl Fn() -> Fut + Send + Sync + 'static, ) -> ArcAsyncDerived<T>
Creates a new async derived computation with an initial value as a fallback, and begins running the
Future eagerly to get the actual first value.
Sourcepub fn new_unsync<Fut>(fun: impl Fn() -> Fut + 'static) -> ArcAsyncDerived<T>where
T: 'static,
Fut: Future<Output = T> + 'static,
pub fn new_unsync<Fut>(fun: impl Fn() -> Fut + 'static) -> ArcAsyncDerived<T>where
T: 'static,
Fut: Future<Output = T> + 'static,
Creates a new async derived computation that will be guaranteed to run on the current thread.
This runs eagerly: i.e., calls fun once when created and immediately spawns the Future
as a new task.
Sourcepub fn new_unsync_with_initial<Fut>(
initial_value: Option<T>,
fun: impl Fn() -> Fut + 'static,
) -> ArcAsyncDerived<T>where
T: 'static,
Fut: Future<Output = T> + 'static,
pub fn new_unsync_with_initial<Fut>(
initial_value: Option<T>,
fun: impl Fn() -> Fut + 'static,
) -> ArcAsyncDerived<T>where
T: 'static,
Fut: Future<Output = T> + 'static,
Creates a new async derived computation with an initial value as a fallback, and begins running the
Future eagerly to get the actual first value.
Sourcepub fn ready(&self) -> AsyncDerivedReadyFuture ⓘ
pub fn ready(&self) -> AsyncDerivedReadyFuture ⓘ
Returns a Future that is ready when this resource has next finished loading.
Source§impl<T> ArcAsyncDerived<T>where
T: 'static,
impl<T> ArcAsyncDerived<T>where
T: 'static,
Sourcepub fn by_ref(&self) -> AsyncDerivedRefFuture<T> ⓘ
pub fn by_ref(&self) -> AsyncDerivedRefFuture<T> ⓘ
Returns a Future that resolves when the computation is finished, and accesses the inner
value by reference rather than by cloning it.
Trait Implementations§
Source§impl<T> Clone for ArcAsyncDerived<T>
impl<T> Clone for ArcAsyncDerived<T>
Source§fn clone(&self) -> ArcAsyncDerived<T>
fn clone(&self) -> ArcAsyncDerived<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<T> Debug for ArcAsyncDerived<T>
impl<T> Debug for ArcAsyncDerived<T>
Source§impl<T> DefinedAt for ArcAsyncDerived<T>
impl<T> DefinedAt for ArcAsyncDerived<T>
Source§fn defined_at(&self) -> Option<&'static Location<'static>>
fn defined_at(&self) -> Option<&'static Location<'static>>
None in
release mode.Source§impl<T> From<ArcAsyncDerived<T>> for AsyncDerived<T>
impl<T> From<ArcAsyncDerived<T>> for AsyncDerived<T>
Source§fn from(value: ArcAsyncDerived<T>) -> AsyncDerived<T>
fn from(value: ArcAsyncDerived<T>) -> AsyncDerived<T>
Source§impl<T> From<AsyncDerived<T>> for ArcAsyncDerived<T>
impl<T> From<AsyncDerived<T>> for ArcAsyncDerived<T>
Source§fn from(value: AsyncDerived<T>) -> ArcAsyncDerived<T>
fn from(value: AsyncDerived<T>) -> ArcAsyncDerived<T>
Source§impl<T> FromLocal<ArcAsyncDerived<T>> for AsyncDerived<T, LocalStorage>where
T: 'static,
impl<T> FromLocal<ArcAsyncDerived<T>> for AsyncDerived<T, LocalStorage>where
T: 'static,
Source§fn from_local(value: ArcAsyncDerived<T>) -> AsyncDerived<T, LocalStorage>
fn from_local(value: ArcAsyncDerived<T>) -> AsyncDerived<T, LocalStorage>
Source§impl<T> IntoFuture for ArcAsyncDerived<T>where
T: Clone + 'static,
impl<T> IntoFuture for ArcAsyncDerived<T>where
T: Clone + 'static,
Source§type IntoFuture = AsyncDerivedFuture<T>
type IntoFuture = AsyncDerivedFuture<T>
Source§fn into_future(self) -> <ArcAsyncDerived<T> as IntoFuture>::IntoFuture
fn into_future(self) -> <ArcAsyncDerived<T> as IntoFuture>::IntoFuture
Source§impl<T> IsDisposed for ArcAsyncDerived<T>where
T: 'static,
impl<T> IsDisposed for ArcAsyncDerived<T>where
T: 'static,
Source§fn is_disposed(&self) -> bool
fn is_disposed(&self) -> bool
true, the signal cannot be accessed without a panic.Source§impl<T> Notify for ArcAsyncDerived<T>where
T: 'static,
impl<T> Notify for ArcAsyncDerived<T>where
T: 'static,
Source§impl<T> ReactiveNode for ArcAsyncDerived<T>
impl<T> ReactiveNode for ArcAsyncDerived<T>
Source§fn mark_dirty(&self)
fn mark_dirty(&self)
Source§fn mark_check(&self)
fn mark_check(&self)
Source§fn mark_subscribers_check(&self)
fn mark_subscribers_check(&self)
Source§fn update_if_necessary(&self) -> bool
fn update_if_necessary(&self) -> bool
Source§impl<T> ReadUntracked for ArcAsyncDerived<T>where
T: 'static,
impl<T> ReadUntracked for ArcAsyncDerived<T>where
T: 'static,
Source§type Value = ReadGuard<Option<T>, AsyncPlain<Option<T>>>
type Value = ReadGuard<Option<T>, AsyncPlain<Option<T>>>
Source§fn try_read_untracked(
&self,
) -> Option<<ArcAsyncDerived<T> as ReadUntracked>::Value>
fn try_read_untracked( &self, ) -> Option<<ArcAsyncDerived<T> as ReadUntracked>::Value>
None if the signal has already been disposed.Source§fn read_untracked(&self) -> Self::Value
fn read_untracked(&self) -> Self::Value
Source§fn custom_try_read(&self) -> Option<Option<Self::Value>>
fn custom_try_read(&self) -> Option<Option<Self::Value>>
Read::try_read implementation despite it being auto implemented. Read moreSource§impl<T> Source for ArcAsyncDerived<T>
impl<T> Source for ArcAsyncDerived<T>
Source§fn add_subscriber(&self, subscriber: AnySubscriber)
fn add_subscriber(&self, subscriber: AnySubscriber)
Source§fn remove_subscriber(&self, subscriber: &AnySubscriber)
fn remove_subscriber(&self, subscriber: &AnySubscriber)
Source§fn clear_subscribers(&self)
fn clear_subscribers(&self)
Source§impl<T> Subscriber for ArcAsyncDerived<T>
impl<T> Subscriber for ArcAsyncDerived<T>
Source§fn add_source(&self, source: AnySource)
fn add_source(&self, source: AnySource)
Source§fn clear_sources(&self, subscriber: &AnySubscriber)
fn clear_sources(&self, subscriber: &AnySubscriber)
Source§impl<T> ToAnySource for ArcAsyncDerived<T>where
T: 'static,
impl<T> ToAnySource for ArcAsyncDerived<T>where
T: 'static,
Source§fn to_any_source(&self) -> AnySource
fn to_any_source(&self) -> AnySource
Source§impl<T> ToAnySubscriber for ArcAsyncDerived<T>where
T: 'static,
impl<T> ToAnySubscriber for ArcAsyncDerived<T>where
T: 'static,
Source§fn to_any_subscriber(&self) -> AnySubscriber
fn to_any_subscriber(&self) -> AnySubscriber
Source§impl<T> Write for ArcAsyncDerived<T>where
T: 'static,
impl<T> Write for ArcAsyncDerived<T>where
T: 'static,
Source§fn try_write(&self) -> Option<impl UntrackableGuard>
fn try_write(&self) -> Option<impl UntrackableGuard>
None if the signal has already been disposed.Source§fn try_write_untracked(&self) -> Option<impl DerefMut>
fn try_write_untracked(&self) -> Option<impl DerefMut>
None if the signal has already been disposed.Source§fn write(&self) -> impl UntrackableGuard
fn write(&self) -> impl UntrackableGuard
Source§fn write_untracked(&self) -> impl DerefMut
fn write_untracked(&self) -> impl DerefMut
Auto Trait Implementations§
impl<T> Freeze for ArcAsyncDerived<T>
impl<T> !RefUnwindSafe for ArcAsyncDerived<T>
impl<T> Send for ArcAsyncDerived<T>
impl<T> Sync for ArcAsyncDerived<T>
impl<T> Unpin for ArcAsyncDerived<T>
impl<T> !UnwindSafe for ArcAsyncDerived<T>
Blanket Implementations§
Source§impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
Source§fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
Source§fn adapt_into(self) -> D
fn adapt_into(self) -> D
Source§impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
Source§fn arrays_from(colors: C) -> T
fn arrays_from(colors: C) -> T
Source§impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
Source§fn arrays_into(self) -> C
fn arrays_into(self) -> C
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<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
impl<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
Source§type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
parameters when converting.Source§fn cam16_into_unclamped(
self,
parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>,
) -> T
fn cam16_into_unclamped( self, parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>, ) -> T
self into C, using the provided parameters.Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
Source§fn components_from(colors: C) -> T
fn components_from(colors: C) -> T
Source§impl<T> FromAngle<T> for T
impl<T> FromAngle<T> for T
Source§fn from_angle(angle: T) -> T
fn from_angle(angle: T) -> T
angle.Source§impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
Source§fn from_stimulus(other: U) -> T
fn from_stimulus(other: U) -> T
other into Self, while performing the appropriate scaling,
rounding and clamping.Source§impl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
impl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
Source§fn into_angle(self) -> U
fn into_angle(self) -> U
T.Source§impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
Source§type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
parameters when converting.Source§fn into_cam16_unclamped(
self,
parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>,
) -> T
fn into_cam16_unclamped( self, parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>, ) -> T
self into C, using the provided parameters.Source§impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
Source§fn into_color(self) -> U
fn into_color(self) -> U
Source§impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
Source§fn into_color_unclamped(self) -> U
fn into_color_unclamped(self) -> U
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 moreSource§impl<El, T, Marker> IntoElementMaybeSignal<T, Marker> for Elwhere
El: IntoElementMaybeSignalType<T, Marker>,
Marker: ?Sized,
impl<El, T, Marker> IntoElementMaybeSignal<T, Marker> for Elwhere
El: IntoElementMaybeSignalType<T, Marker>,
Marker: ?Sized,
fn into_element_maybe_signal(self) -> ElementMaybeSignal<T>
Source§impl<T, Js> IntoElementMaybeSignalType<T, Element> for Js
impl<T, Js> IntoElementMaybeSignalType<T, Element> for Js
fn into_element_maybe_signal_type(self) -> ElementMaybeSignalType<T>
Source§impl<T, V, E> IntoElementMaybeSignalType<T, OptionSignalMarker> for V
impl<T, V, E> IntoElementMaybeSignalType<T, OptionSignalMarker> for V
fn into_element_maybe_signal_type(self) -> ElementMaybeSignalType<T>
Source§impl<T, V, E> IntoElementMaybeSignalType<T, SignalMarker> for V
impl<T, V, E> IntoElementMaybeSignalType<T, SignalMarker> for V
fn into_element_maybe_signal_type(self) -> ElementMaybeSignalType<T>
Source§impl<El, T, Marker> IntoElementsMaybeSignal<T, Marker> for Elwhere
El: IntoElementsMaybeSignalType<T, Marker>,
Marker: ?Sized,
impl<El, T, Marker> IntoElementsMaybeSignal<T, Marker> for Elwhere
El: IntoElementsMaybeSignalType<T, Marker>,
Marker: ?Sized,
fn into_elements_maybe_signal(self) -> ElementsMaybeSignal<T>
Source§impl<T, Js> IntoElementsMaybeSignalType<T, Element> for Js
impl<T, Js> IntoElementsMaybeSignalType<T, Element> for Js
fn into_elements_maybe_signal_type(self) -> ElementsMaybeSignalType<T>
Source§impl<T, V, E> IntoElementsMaybeSignalType<T, SignalMarker> for V
impl<T, V, E> IntoElementsMaybeSignalType<T, SignalMarker> for V
fn into_elements_maybe_signal_type(self) -> ElementsMaybeSignalType<T>
Source§impl<T, Js, C, G> IntoElementsMaybeSignalType<T, SignalVecMarker> for G
impl<T, Js, C, G> IntoElementsMaybeSignalType<T, SignalVecMarker> for G
fn into_elements_maybe_signal_type(self) -> ElementsMaybeSignalType<T>
Source§impl<T, Js, C, G> IntoElementsMaybeSignalType<T, SignalVecOptionMarker> for G
impl<T, Js, C, G> IntoElementsMaybeSignalType<T, SignalVecOptionMarker> for G
fn into_elements_maybe_signal_type(self) -> ElementsMaybeSignalType<T>
Source§impl<T> IntoStimulus<T> for T
impl<T> IntoStimulus<T> for T
Source§fn into_stimulus(self) -> T
fn into_stimulus(self) -> T
self into T, while performing the appropriate scaling,
rounding and clamping.Source§impl<T> Read for Twhere
T: Track + ReadUntracked,
impl<T> Read for Twhere
T: Track + ReadUntracked,
Source§impl<T> Set for Twhere
T: Update + IsDisposed,
impl<T> Set for Twhere
T: Update + IsDisposed,
Source§impl<T> StorageAccess<T> for T
impl<T> StorageAccess<T> for T
Source§fn as_borrowed(&self) -> &T
fn as_borrowed(&self) -> &T
Source§fn into_taken(self) -> T
fn into_taken(self) -> T
Source§impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
Source§type Error = <C as TryFromComponents<T>>::Error
type Error = <C as TryFromComponents<T>>::Error
try_into_colors fails to cast.Source§fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
Source§impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
Source§fn try_into_color(self) -> Result<U, OutOfBounds<U>>
fn try_into_color(self) -> Result<U, OutOfBounds<U>>
OutOfBounds error is returned which contains
the unclamped color. Read moreSource§impl<C, U> UintsFrom<C> for Uwhere
C: IntoUints<U>,
impl<C, U> UintsFrom<C> for Uwhere
C: IntoUints<U>,
Source§fn uints_from(colors: C) -> U
fn uints_from(colors: C) -> U
Source§impl<C, U> UintsInto<C> for Uwhere
C: FromUints<U>,
impl<C, U> UintsInto<C> for Uwhere
C: FromUints<U>,
Source§fn uints_into(self) -> C
fn uints_into(self) -> C
Source§impl<T> Update for Twhere
T: Write,
impl<T> Update for Twhere
T: Write,
Source§fn try_maybe_update<U>(
&self,
fun: impl FnOnce(&mut <T as Update>::Value) -> (bool, U),
) -> Option<U>
fn try_maybe_update<U>( &self, fun: impl FnOnce(&mut <T as Update>::Value) -> (bool, U), ) -> Option<U>
(true, _), and returns the value returned by the update function,
or None if the signal has already been disposed.Source§fn update(&self, fun: impl FnOnce(&mut Self::Value))
fn update(&self, fun: impl FnOnce(&mut Self::Value))
Source§impl<T> UpdateUntracked for Twhere
T: Write,
impl<T> UpdateUntracked for Twhere
T: Write,
Source§fn try_update_untracked<U>(
&self,
fun: impl FnOnce(&mut <T as UpdateUntracked>::Value) -> U,
) -> Option<U>
fn try_update_untracked<U>( &self, fun: impl FnOnce(&mut <T as UpdateUntracked>::Value) -> U, ) -> Option<U>
None if the signal has already been disposed.
Does not notify subscribers that the signal has changed.Source§impl<T> With for Twhere
T: Read,
impl<T> With for Twhere
T: Read,
Source§type Value = <<T as Read>::Value as Deref>::Target
type Value = <<T as Read>::Value as Deref>::Target
Source§impl<T> WithUntracked for Twhere
T: DefinedAt + ReadUntracked,
impl<T> WithUntracked for Twhere
T: DefinedAt + ReadUntracked,
Source§type Value = <<T as ReadUntracked>::Value as Deref>::Target
type Value = <<T as ReadUntracked>::Value as Deref>::Target
Source§fn try_with_untracked<U>(
&self,
fun: impl FnOnce(&<T as WithUntracked>::Value) -> U,
) -> Option<U>
fn try_with_untracked<U>( &self, fun: impl FnOnce(&<T as WithUntracked>::Value) -> U, ) -> Option<U>
None if the signal has already been disposed.