//! A shutdown channel. //! //! Each worker holds the `Sender` half. When all the `Sender` halves are //! dropped, the `Receiver` receives a notification.
pub(super) fn channel() -> (Sender, Receiver) { let (tx, rx) = oneshot::channel(); let tx = Sender { _tx: Arc::new(tx) }; let rx = Receiver { rx };
(tx, rx)
}
impl Receiver { /// Blocks the current thread until all `Sender` handles drop. /// /// If `timeout` is `Some`, the thread is blocked for **at most** `timeout` /// duration. If `timeout` is `None`, then the thread is blocked until the /// shutdown signal is received. /// /// If the timeout has elapsed, it returns `false`, otherwise it returns `true`. pub(crate) fn wait(&mutself, timeout: Option<Duration>) -> bool { usecrate::runtime::context::try_enter_blocking_region;
if timeout == Some(Duration::from_nanos(0)) { returnfalse;
}
letmut e = match try_enter_blocking_region() {
Some(enter) => enter,
_ => { if std::thread::panicking() { // Don't panic in a panic returnfalse;
} else {
panic!( "Cannot drop a runtime in a context where blocking is not allowed. \
This happens when a runtime is dropped from within an asynchronous context."
);
}
}
};
// The oneshot completes with an Err // // If blocking fails to wait, this indicates a problem parking the // current thread (usually, shutting down a runtime stored in a // thread-local). iflet Some(timeout) = timeout {
e.block_on_timeout(&mutself.rx, timeout).is_ok()
} else { let _ = e.block_on(&mutself.rx); true
}
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.0 Sekunden
(vorverarbeitet am 2026-06-23)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.