Skip to content

Commit

Permalink
use weak
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverb123 committed Feb 6, 2025
1 parent e35230b commit c12685c
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions rust/batch-import-worker/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,12 @@ pub async fn main() -> Result<(), Error> {
fn start_init_liveness_loop(liveness: Arc<HealthHandle>) -> Arc<AtomicBool> {
let run = Arc::new(AtomicBool::new(true));
let liveness = liveness.clone();
let run_clone = run.clone();
let run_weak = Arc::downgrade(&run); // Use a weak so if the returned arc is dropped the task will exit
tokio::task::spawn(async move {
while run_clone.load(Ordering::Relaxed) {
let Some(flag) = run_weak.upgrade() else {
return;
};
while flag.load(Ordering::Relaxed) {
liveness.report_healthy().await;
tokio::time::sleep(Duration::from_secs(5)).await;
}
Expand Down

0 comments on commit c12685c

Please sign in to comment.