Skip to content

Commit 7cedc13

Browse files
committed
perf(client): create DispatchGone error only if needed
1 parent 1028f27 commit 7cedc13

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/client/dispatch.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -226,28 +226,31 @@ pub(crate) enum Callback<T, U> {
226226

227227
impl<T, U> Drop for Callback<T, U> {
228228
fn drop(&mut self) {
229-
// FIXME(nox): What errors do we want here?
230-
let error = crate::Error::new_user_dispatch_gone().with(if std::thread::panicking() {
231-
"user code panicked"
232-
} else {
233-
"runtime dropped the dispatch task"
234-
});
235-
236229
match self {
237230
Callback::Retry(tx) => {
238231
if let Some(tx) = tx.take() {
239-
let _ = tx.send(Err((error, None)));
232+
let _ = tx.send(Err((dispatch_gone(), None)));
240233
}
241234
}
242235
Callback::NoRetry(tx) => {
243236
if let Some(tx) = tx.take() {
244-
let _ = tx.send(Err(error));
237+
let _ = tx.send(Err(dispatch_gone()));
245238
}
246239
}
247240
}
248241
}
249242
}
250243

244+
#[cold]
245+
fn dispatch_gone() -> crate::Error {
246+
// FIXME(nox): What errors do we want here?
247+
crate::Error::new_user_dispatch_gone().with(if std::thread::panicking() {
248+
"user code panicked"
249+
} else {
250+
"runtime dropped the dispatch task"
251+
})
252+
}
253+
251254
impl<T, U> Callback<T, U> {
252255
#[cfg(feature = "http2")]
253256
pub(crate) fn is_canceled(&self) -> bool {

0 commit comments

Comments
 (0)