veilid/veilid-core/src/xx/single_shot_eventual.rs
John Smith 028e02f942 lints
2021-11-27 12:44:21 -05:00

40 lines
789 B
Rust

use super::*;
pub struct SingleShotEventual<T>
where
T: Unpin + Clone,
{
eventual: EventualValueClone<T>,
drop_value: T,
}
impl<T> Drop for SingleShotEventual<T>
where
T: Unpin + Clone,
{
fn drop(&mut self) {
self.eventual.resolve(self.drop_value.clone());
}
}
impl<T> SingleShotEventual<T>
where
T: Unpin + Clone,
{
pub fn new(drop_value: T) -> Self {
Self {
eventual: EventualValueClone::new(),
drop_value,
}
}
// Can only call this once, it consumes the eventual
pub fn resolve(self, value: T) -> EventualResolvedFuture<EventualValueClone<T>> {
self.eventual.resolve(value)
}
pub fn instance(&self) -> EventualValueCloneFuture<T> {
self.eventual.instance()
}
}