use crate::error::AttemptFailure;
use super::sync_attempt::SyncAttempt;
pub(in crate::executor) struct SyncValueOperation<T, F> {
operation: F,
value: Option<T>,
}
impl<T, F> SyncValueOperation<T, F> {
pub(in crate::executor) fn new(operation: F) -> Self {
Self {
operation,
value: None,
}
}
pub(in crate::executor) fn into_value(self) -> T {
self.value
.expect("retry loop succeeded without an operation value")
}
}
impl<T, E, F> SyncAttempt<E> for SyncValueOperation<T, F>
where
F: FnMut() -> Result<T, E>,
{
fn call(&mut self) -> Result<(), AttemptFailure<E>> {
match (self.operation)() {
Ok(value) => {
self.value = Some(value);
Ok(())
}
Err(error) => Err(AttemptFailure::Error(error)),
}
}
}