1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use crate::{Future, Select, Shared, ToValue, Vm, VmError};
#[derive(Debug)]
pub enum Awaited {
Future(Shared<Future>),
Select(Select),
}
impl Awaited {
pub(crate) async fn into_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(())
}
}