Skip to content

Commit

Permalink
perf(client): create DispatchGone error only if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmonstar committed Jun 21, 2024
1 parent 1028f27 commit 7cedc13
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/client/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,28 +226,31 @@ pub(crate) enum Callback<T, U> {

impl<T, U> Drop for Callback<T, U> {
fn drop(&mut self) {
// FIXME(nox): What errors do we want here?
let error = crate::Error::new_user_dispatch_gone().with(if std::thread::panicking() {
"user code panicked"
} else {
"runtime dropped the dispatch task"
});

match self {
Callback::Retry(tx) => {
if let Some(tx) = tx.take() {
let _ = tx.send(Err((error, None)));
let _ = tx.send(Err((dispatch_gone(), None)));
}
}
Callback::NoRetry(tx) => {
if let Some(tx) = tx.take() {
let _ = tx.send(Err(error));
let _ = tx.send(Err(dispatch_gone()));
}
}
}
}
}

#[cold]
fn dispatch_gone() -> crate::Error {
// FIXME(nox): What errors do we want here?
crate::Error::new_user_dispatch_gone().with(if std::thread::panicking() {
"user code panicked"
} else {
"runtime dropped the dispatch task"
})
}

impl<T, U> Callback<T, U> {
#[cfg(feature = "http2")]
pub(crate) fn is_canceled(&self) -> bool {
Expand Down

0 comments on commit 7cedc13

Please sign in to comment.