Skip to main content

watch

Function watch 

Source
pub fn watch(
    kind: SensorKind,
    on_sample: impl FnMut(SensorReading) + Send + 'static,
) -> Watch
Expand description

Subscribe to a sensor. Samples arrive on an unspecified BACKGROUND thread roughly every SAMPLE_MS until the returned Watch is dropped.

Nothing is delivered before the platform’s first event, so a device that never reports (no such sensor, an emulator without passthrough) simply produces no samples — ask is_available to tell that apart from “not yet”.

In a Day app, bind the handle to the page’s scope so the subscription ends with it:

let watch = day_part_sensors::watch(SensorKind::Accelerometer, move |r| latest.set(r));
day_reactive::Scope::current().on_cleanup(move || drop(watch));
Day API ↩ Guides· daybrite.dev