pub struct OneShot[X] { priv mut state : X?; priv wake : @cond_var.Cond }
pub fn[X] OneShot::OneShot() -> OneShot[X] { { state: None, wake: @cond_var.Cond() } }
pub fn[X] OneShot::complete(self : OneShot[X], value : X) -> Result[Unit, X] {
if self.state is Some(_) { Err(value) } else { self.state = Some(value); self.wake.broadcast(); Ok(()) }
}
pub async fn[X] OneShot::wait(self : OneShot[X]) -> X {
if @async.is_being_cancelled() { @async.pause() }
match self.state { Some(v) => v; None => { self.wake.wait(); self.state.unwrap() } }
}