mirror of
https://github.com/embassy-rs/embassy.git
synced 2024-11-21 22:32:29 +00:00
fut: add poll_once
This commit is contained in:
parent
e1161dfc80
commit
9e8de5f596
@ -31,3 +31,15 @@ pub fn block_on<F: Future>(mut fut: F) -> F::Output {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Poll a future once.
|
||||
pub fn poll_once<F: Future>(mut fut: F) -> Poll<F::Output> {
|
||||
// safety: we don't move the future after this line.
|
||||
let mut fut = unsafe { Pin::new_unchecked(&mut fut) };
|
||||
|
||||
let raw_waker = RawWaker::new(ptr::null(), &VTABLE);
|
||||
let waker = unsafe { Waker::from_raw(raw_waker) };
|
||||
let mut cx = Context::from_waker(&waker);
|
||||
|
||||
fut.as_mut().poll(&mut cx)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user