Closed
Description
struct Check<'a, F: Future + ?Sized>(Pin<&'a mut F>);
impl<F: Future + ?Sized> Future for Check<'_, F> {
type Output = Poll<F::Output>;
fn poll(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
Poll::Ready(self.0.as_mut().poll(cx))
}
}
async fn checkup(tasks: Vec<Task>) {
for mut task in tasks {
if let Poll::Ready(val) = Check(task.fut.as_mut()).await {
handle(val);
cleanup(task);
}
}
}
I've seen this pattern come up in a few different projects now, and it seems generic enough for the futures
crate. It could well be too niche though.