Trait silkenweb_task::TaskSignal

source ·
pub trait TaskSignal: Signal {
    // Required methods
    fn to_mutable(self) -> ReadOnlyMutable<Self::Item>;
    fn spawn_for_each<U, F>(self, callback: F)
       where U: Future<Output = ()> + 'static,
             F: FnMut(Self::Item) -> U + 'static;
}
Expand description

Signal methods that require a task queue.

Required Methods§

source

fn to_mutable(self) -> ReadOnlyMutable<Self::Item>

Convert self to a Mutable.

This uses the microtask queue to spawn a future that drives the signal. The resulting Mutable can be used to memoize the signal, allowing many signals to be derived from it.

§Example
let source = Mutable::new(0);
let signal = source.signal();

// A scope isn't required on browser platforms
sync_scope(|| {
    let copy = signal.to_mutable();
    assert_eq!(copy.get(), 0);
    source.set(1);
    run_tasks_sync();
    assert_eq!(copy.get(), 1);
});
source

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

Run callback on each signal value.

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> TaskSignal for Sig
where Sig: Signal + 'static,