Skip to content

Commit fe22bb9

Browse files
committed
fix(watcher): handle watcher channels closing
1 parent f3db92d commit fe22bb9

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

crates/watcher/src/lib.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,12 @@ where
3737
time_interval.tick().await;
3838
let result = function().await;
3939
match result {
40-
Ok(value) => tx.send(value).expect("Failed to update channel"),
40+
Ok(value) => {
41+
if tx.send(value).is_err() {
42+
tracing::debug!("Watcher channel closed, stopping watcher task");
43+
break;
44+
}
45+
}
4146
Err(err) => {
4247
// TODO mark it as delayed
4348
tracing::warn!(error = %err, "There was an error while updating watcher");
@@ -79,7 +84,10 @@ where
7984
let current_val_1 = receiver_1.borrow().clone();
8085
let current_val_2 = receiver_2.borrow().clone();
8186
let mapped_value = map_function((current_val_1, current_val_2));
82-
tx.send(mapped_value).expect("Failed to update channel");
87+
if tx.send(mapped_value).is_err() {
88+
tracing::debug!("Watcher channel closed, stopping combined watcher task");
89+
break;
90+
}
8391
}
8492
});
8593
rx
@@ -138,7 +146,10 @@ where
138146

139147
let current_val = receiver.borrow().clone();
140148
let mapped_value = map_function(current_val);
141-
tx.send(mapped_value).expect("Failed to update channel");
149+
if tx.send(mapped_value).is_err() {
150+
tracing::debug!("Watcher channel closed, stopping mapped watcher task");
151+
break;
152+
}
142153
}
143154
});
144155
rx

0 commit comments

Comments
 (0)