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§

source

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]);
});
source

fn spawn_for_each<U, F>(self, callback: F)
where U: Future<Output = ()> + 'static, F: FnMut(VecDiff<Self::Item>) -> U + 'static,

Run callback on each signal delta.

The future is spawned on the microtask queue. This is equivalent to spawn_local(sig.for_each(callback)).

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<Sig> TaskSignalVec for Sig
where Self::Item: Clone + 'static, Sig: SignalVec + 'static,