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§
sourcefn to_mutable(self) -> ReadOnlyMutable<Self::Item>
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);
});
Object Safety§
This trait is not object safe.