use recursive poll

This commit is contained in:
fakeshadow 2021-01-14 03:03:03 +08:00
parent 2394890bf1
commit e7ec216842
1 changed files with 14 additions and 18 deletions

View File

@ -152,26 +152,22 @@ where
type Output = Fut::Output;
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
loop {
match self.as_mut().project() {
ErrorHandlersProj::ServiceFuture { fut, handlers } => {
let res = ready!(fut.poll(cx))?;
match handlers.get(&res.status()) {
Some(handler) => match handler(res)? {
ErrorHandlerResponse::Response(res) => {
return Poll::Ready(Ok(res))
ErrorHandlerResponse::Response(res) => Poll::Ready(Ok(res)),
ErrorHandlerResponse::Future(fut) => {
self.as_mut()
.set(ErrorHandlersFuture::HandlerFuture { fut });
self.poll(cx)
}
ErrorHandlerResponse::Future(fut) => self
.as_mut()
.set(ErrorHandlersFuture::HandlerFuture { fut }),
},
None => return Poll::Ready(Ok(res)),
}
}
ErrorHandlersProj::HandlerFuture { fut } => {
return fut.as_mut().poll(cx)
None => Poll::Ready(Ok(res)),
}
}
ErrorHandlersProj::HandlerFuture { fut } => fut.as_mut().poll(cx),
}
}
}