Revert "Revert "use tokio::sync::Receiver::wait_for""

This reverts commit eaf270c648.
This commit is contained in:
Christian Schwarz
2023-05-25 14:58:49 +02:00
parent 05a2fe08d1
commit f18d9f555b

View File

@@ -1704,15 +1704,12 @@ impl Tenant {
///
/// This function is not cancel-safe!
pub async fn set_stopping(&self) {
// Get the rx before checking state inside send_if_modified.
// This way, when we later rx.changed().await, we won't have missed
// any state changes.
// `Activating` is a transient state during which no external state transitions are supported.
let mut rx = self.state.subscribe();
while *rx.borrow() == TenantState::Activating {
rx.changed()
.await
.expect("we're a method on Tenant, so, we're keeping self.state alive here");
}
rx.wait_for(|state| state != TenantState::Activating)
.await
.expect("cannot drop self.state while on a &self method");
let mut stopping = false;
self.state.send_modify(|current_state| {
match current_state {
@@ -1750,12 +1747,12 @@ impl Tenant {
}
pub async fn set_broken(&self, reason: String) {
// `Activating` is a transient state during which no external state transitions are supported.
let mut rx = self.state.subscribe();
while *rx.borrow() == TenantState::Activating {
rx.changed()
.await
.expect("we're a method on Tenant, so, we're keeping self.state alive here");
}
rx.wait_for(|state| state != TenantState::Activating)
.await
.expect("cannot drop self.state while on a &self method");
self.state.send_modify(|current_state| {
match *current_state {
TenantState::Activating => {