alternator/
poller.rs

1use futures::task;
2use std::future::Future;
3use std::pin::Pin;
4use std::task::{Context, Poll};
5
6/// The simplest possible executor.
7/// Does not support waking.
8pub struct Poller<T: Future + Unpin>(T);
9
10impl<T: Future + Unpin> Poller<T> {
11    pub fn new(x: T) -> Self {
12        Self(x)
13    }
14
15    pub fn poll_once(&mut self) -> Option<<T as Future>::Output> {
16        let mut ctx = Context::from_waker(task::noop_waker_ref());
17        match Pin::new(&mut self.0).poll(&mut ctx) {
18            Poll::Ready(x) => Some(x),
19            Poll::Pending => None,
20        }
21    }
22}