Ensure unwind safety in dispatch sequence.

Ensure await safety/efficiency in retirement sequence.

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk
2025-07-30 21:18:11 +00:00
parent bd0c3e33e2
commit 0b15ab2006
2 changed files with 10 additions and 9 deletions

View File

@@ -1,6 +1,7 @@
use std::{ops::Range, sync::Arc};
use tokio::sync::{watch, watch::Sender};
use futures::TryFutureExt;
use tokio::sync::watch::Sender;
use tuwunel_core::{
Result, err, utils,
utils::two_phase_counter::{Counter as TwoPhaseCounter, Permit as TwoPhasePermit},
@@ -24,7 +25,7 @@ impl Data {
pub(super) fn new(args: &crate::Args<'_>) -> Self {
let db = args.db.clone();
let count = Self::stored_count(&args.db["global"]).expect("initialize global counter");
let retires = watch::channel(count).0;
let retires = Sender::new(count);
Self {
db: args.db.clone(),
global: args.db["global"].clone(),
@@ -51,9 +52,9 @@ impl Data {
self.retires
.subscribe()
.wait_for(|retired| retired.ge(count))
.await
.map(|retired| *retired)
.map_ok(|retired| *retired)
.map_err(|e| err!(debug_error!("counter channel error {e:?}")))
.await
}
#[inline]