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
//! Executable asynchronous task
use {
alloc::boxed::Box,
core::{
future::Future,
pin::Pin,
task::{Context, Poll},
},
};
/// Wrapper around a pinned, boxed future
pub struct Task {
future: Pin<Box<dyn Future<Output = ()>>>,
}
impl Task {
/// Create a new task from a future
pub fn new(future: impl Future<Output = ()> + 'static) -> Task {
Task {
future: Box::pin(future),
}
}
pub fn poll(&mut self, context: &mut Context) -> Poll<()> {
self.future.as_mut().poll(context)
}
}