pub struct AnalysisProgress<W: WarningHandling = WarningsAsErrors> { /* private fields */ }Expand description
An in-progress analysis operation for a single position.
Implementations§
Source§impl<W: WarningHandling> AnalysisProgress<W>
impl<W: WarningHandling> AnalysisProgress<W>
Sourcepub async fn finish(self) -> WarningResult<Option<AnalysisResult>, W>
pub async fn finish(self) -> WarningResult<Option<AnalysisResult>, W>
Waits for the analysis to finish and returns the result.
If the analysis was terminated before any search was performed, returns Ok(None).
Sourcepub async fn poll(
self,
) -> ControlFlow<WarningResult<Option<AnalysisResult>, W>, Self>
pub async fn poll( self, ) -> ControlFlow<WarningResult<Option<AnalysisResult>, W>, Self>
Waits for an analysis update.
This is mainly useful when using AnalysisRequest::report_during_search_every. Otherwise, it’s simpler to
just call finish to wait for the final result.
If the analysis is finished, it consumes this object and returns ControlFlow::Break containing the final
result. If a partial result is available, it returns ControlFlow::Continue containing this object again,
which can be read using read or polled again for the next update.
This method (in combination with read) is conceptually similar to Tokio’s
watch channel. It provides a way to follow the latest information as it becomes
available without any danger of falling behind.
§Example
loop {
match progress.poll().await {
ControlFlow::Break(result) => {
match result {
Ok(Some(result)) => {
println!("Winrate: {:.1}%", result.root_info.winrate * 100.0);
}
Ok(None) => println!("No results"),
Err(e) => println!("Error: {e}"),
}
break;
}
ControlFlow::Continue(p) => {
progress = p;
if let Ok(Some(result)) = progress.read().await.as_ref() {
println!(
"Winrate: {:.1}% Visits: {}",
result.root_info.winrate * 100.0,
result.root_info.visits
);
}
}
};
}Sourcepub async fn read(
&self,
) -> RwLockReadGuard<'_, WarningResult<Option<AnalysisResult>, W>>
pub async fn read( &self, ) -> RwLockReadGuard<'_, WarningResult<Option<AnalysisResult>, W>>
Reads the latest analysis result available.
See also: poll