use sim_kernel::Ref;
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum AsyncPoll {
Pending,
Ready(Ref),
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct AsyncTask {
result: Ref,
pending_polls: usize,
polls: usize,
}
impl AsyncTask {
pub fn ready_after(pending_polls: usize, result: Ref) -> Self {
Self {
result,
pending_polls,
polls: 0,
}
}
pub fn poll(&mut self) -> AsyncPoll {
if self.polls < self.pending_polls {
self.polls += 1;
return AsyncPoll::Pending;
}
AsyncPoll::Ready(self.result.clone())
}
}