use std::{
fmt::Debug,
sync::Mutex,
task::{Context, Poll},
};
use futures_core::future::BoxFuture;
pub struct BoxSyncFuture<T>(Mutex<BoxFuture<'static, T>>);
impl<T> Debug for BoxSyncFuture<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("BoxSyncFuture { .. }").finish()
}
}
impl<T> BoxSyncFuture<T> {
#[must_use]
pub fn new(fut: BoxFuture<'static, T>) -> Self {
Self(Mutex::new(fut))
}
pub fn poll_unpin(&mut self, cx: &mut Context<'_>) -> Poll<T> {
self.0.get_mut().unwrap().as_mut().poll(cx)
}
}
impl<T> From<BoxFuture<'static, T>> for BoxSyncFuture<T> {
fn from(fut: BoxFuture<'static, T>) -> Self {
Self::new(fut)
}
}