pub struct EagerCompute<'f, C: 'f> {
pub context: C,
/* private fields */
}
Expand description
Fields§
§context: C
The data passed to each computed variable on update.
Implementations§
Source§impl<'f, C> EagerCompute<'f, C>
impl<'f, C> EagerCompute<'f, C>
Sourcepub fn new(context: C) -> Self
pub fn new(context: C) -> Self
Creates a new eagerly updating environment. It will only evaluate variables that have been passed explicitly.
Sourcepub fn install<V>(&mut self, computed: ComputedVar<V>)where
V: ComputedValue<Value = (), Context = C> + 'f,
pub fn install<V>(&mut self, computed: ComputedVar<V>)where
V: ComputedValue<Value = (), Context = C> + 'f,
Add the given empty computed variable to this environment. The variable
will be recomputed every time tick
is called if
needed. This is a good way to watch many variables at once.
Note that outdated or uncomputed variables will be computed immediately when first installed.
let a = Var::new(1);
let b = Var::new(2);
let mut eval = EagerCompute::new(());
eval.install(computed! {
a.get();
b.get();
println!("a or b changed")
});
Sourcepub fn install_boxed(&mut self, computed: BoxedComputedVar<'f, (), C>)
pub fn install_boxed(&mut self, computed: BoxedComputedVar<'f, (), C>)
Like install
but relies on the user to pre-box the
computed cell.
Sourcepub fn uninstall_by_id(
&mut self,
node_id: usize,
) -> Option<BoxedComputedVar<'f, (), C>>
pub fn uninstall_by_id( &mut self, node_id: usize, ) -> Option<BoxedComputedVar<'f, (), C>>
Removes the computed variable with the given node id from this environment.
Sourcepub fn tick(&mut self)
pub fn tick(&mut self)
Recompute any installed variables which are outdated. This method may
deadlock if two watchers repeatedly trigger each-other in a loop. If
that is an issue, try using tick_timeout
.
Sourcepub fn tick_timeout(&mut self, end: Instant) -> bool
pub fn tick_timeout(&mut self, end: Instant) -> bool
Recompute any installed variables which are outdated. This method will
return true if all variables are up-to-date or false if the end
time
was reached first.
Sourcepub async fn run_once(&mut self) -> usize
pub async fn run_once(&mut self) -> usize
Returns a future which updates a few installed variables once they
become outdated then resolves to the number of updates performed. This
is similar to run_forever
except it only runs
until at least 1 update has occurred.
Sourcepub async fn run_forever(self)
pub async fn run_forever(self)
Returns a future which runs until dropped, updating any installed
variables when they become outdated. This works well with async event
schedulers since the future will yield until a Var
used by this environment is manually changed, at which point the
future’s context will be instantly notified by
Node::on_write
.