Skip to content

Commit

Permalink
perf: poll handle request future immediately
Browse files Browse the repository at this point in the history
  • Loading branch information
TheWaWaR committed Nov 12, 2023
1 parent 8d81dd2 commit 7d374a7
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions akasa-core/src/protocols/mqtt/online_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,27 @@ where
global,
) {
Ok(Some(request)) => {
*hook_fut = Some(Box::pin(handle_request(
request,
handler.clone(),
global.clone(),
)));
cx.waker().wake_by_ref();
return Poll::Pending;
let mut fut =
Box::pin(handle_request(request, handler.clone(), global.clone()));
let actions = match fut.as_mut().poll(cx) {
Poll::Ready(resp) => match resp {
HookResponse::Normal(Ok(actions)) => actions,
HookResponse::Normal(Err(err_opt)) => {
return Poll::Ready(err_opt)
}
_ => panic!("invalid hook response"),
},
Poll::Pending => {
*hook_fut = Some(fut);
cx.waker().wake_by_ref();
return Poll::Pending;
}
};
for action in actions {
if let Err(err) = session.apply_action(action, global) {
return Poll::Ready(Some(err));
}
}
}
Ok(None) => {}
Err(err_opt) => return Poll::Ready(err_opt),
Expand Down

0 comments on commit 7d374a7

Please sign in to comment.