This commit is contained in:
John Smith
2022-11-26 21:37:23 -05:00
parent 5df46aecae
commit b1bdf76ae8
80 changed files with 865 additions and 700 deletions
+44
View File
@@ -0,0 +1,44 @@
use super::*;
pub struct SingleShotEventual<T>
where
T: Unpin,
{
eventual: EventualValue<T>,
drop_value: Option<T>,
}
impl<T> Drop for SingleShotEventual<T>
where
T: Unpin,
{
fn drop(&mut self) {
if let Some(drop_value) = self.drop_value.take() {
self.eventual.resolve(drop_value);
}
}
}
impl<T> SingleShotEventual<T>
where
T: Unpin,
{
pub fn new(drop_value: Option<T>) -> Self {
Self {
eventual: EventualValue::new(),
drop_value,
}
}
// Can only call this once, it consumes the eventual
pub fn resolve(mut self, value: T) -> EventualResolvedFuture<EventualValue<T>> {
// If we resolve, we don't want to resolve again to the drop value
self.drop_value = None;
// Resolve to the specified value
self.eventual.resolve(value)
}
pub fn instance(&self) -> EventualValueFuture<T> {
self.eventual.instance()
}
}