From 9e8de5f596ffa9036c2343ccc1e69f471a4770eb Mon Sep 17 00:00:00 2001 From: xoviat Date: Sat, 17 Jun 2023 08:11:55 -0500 Subject: [PATCH] fut: add poll_once --- embassy-futures/src/block_on.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/embassy-futures/src/block_on.rs b/embassy-futures/src/block_on.rs index da90351e..77695216 100644 --- a/embassy-futures/src/block_on.rs +++ b/embassy-futures/src/block_on.rs @@ -31,3 +31,15 @@ pub fn block_on(mut fut: F) -> F::Output { } } } + +/// Poll a future once. +pub fn poll_once(mut fut: F) -> Poll { + // 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) +}