pub struct SourceWatch<'finder> { /* private fields */ }Expand description
One consumer’s cursor over a finder’s source-list changes.
Take snapshots and wait through the same watch, so reports published by
concurrent lookups between those operations cannot be missed. A report
during a snapshot remains visible to the next wait. Each consumer must
create its own watch; a watch can move between threads but is not Sync.
let mut watch = finder.watch();
println!("{:?}", watch.current_sources()?);
while watch.wait_for_change(Duration::from_secs(5))? {
println!("{:?}", watch.current_sources()?);
}Implementations§
Source§impl SourceWatch<'_>
impl SourceWatch<'_>
Sourcepub fn current_sources(&mut self) -> Result<Vec<Source>>
pub fn current_sources(&mut self) -> Result<Vec<Source>>
Copy the currently known sources and record the generation before copying, preserving any report that arrives during the snapshot. A failed snapshot leaves the cursor unchanged.
§Errors
Returns the snapshot errors of Finder::current_sources:
Error::UnexpectedSdkResult for a malformed top-level descriptor array,
Error::AllocationFailed for failed result or text reservations,
or Error::ResourceLimit when a snapshot exceeds its copy budgets.
Sourcepub fn wait_for_change(&mut self, timeout: Duration) -> Result<bool>
pub fn wait_for_change(&mut self, timeout: Duration) -> Result<bool>
Wait for a report newer than this consumer’s last snapshot or wait.
Returns true immediately if another lookup already published a report.
A zero timeout reads such reports even while another native waiter is
active; otherwise it makes one nonblocking native query. Returns false
when the timeout expires without a report.
§Errors
Returns Error::InvalidInput if timeout exceeds crate::MAX_TIMEOUT.