Trait silkenweb_task::TaskSignalVec
source · pub trait TaskSignalVec: SignalVec {
// Required methods
fn to_mutable(self) -> MutableVec<Self::Item>;
fn spawn_for_each<U, F>(self, callback: F)
where U: Future<Output = ()> + 'static,
F: FnMut(VecDiff<Self::Item>) -> U + 'static;
}
Expand description
SignalVec
methods that require a task queue.
Required Methods§
sourcefn to_mutable(self) -> MutableVec<Self::Item>
fn to_mutable(self) -> MutableVec<Self::Item>
Convert self
to a MutableVec
.
This uses the microtask queue to spawn a future that drives the signal.
The resulting MutableVec
can be used to memoize the signal, allowing
many signals to be derived from it.
§Example
let source = MutableVec::new();
let signal = source.signal_vec();
// A scope isn't required on browser platforms
sync_scope(|| {
let copy = signal.to_mutable();
assert!(copy.lock_ref().is_empty());
source.lock_mut().push_cloned(1);
run_tasks_sync();
assert_eq!(*copy.lock_ref(), [1]);
});
Object Safety§
This trait is not object safe.