Trait 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)).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<Sig> TaskSignal for Sig
where Sig: Signal + 'static,