use crate::{Future, Select, Shared, ToValue, Vm, VmError};
#[derive(Debug)]
pub enum Awaited {
Future(Shared<Future>),
Select(Select),
}
impl Awaited {
pub(crate) async fn wait_with_vm(self, vm: &mut Vm) -> Result<(), VmError> {
match self {
Self::Future(future) => {
let value = future.borrow_mut()?.await?;
vm.stack_mut().push(value);
vm.advance();
}
Self::Select(select) => {
let (branch, value) = select.await?;
vm.stack_mut().push(value);
vm.stack_mut().push(ToValue::to_value(branch)?);
vm.advance();
}
}
Ok(())
}
}