refactor: Eliminate unnecessary empty Vec constructions.

This commit is contained in:
2026-03-14 11:43:48 -04:00
parent 0ebb5e79dd
commit e89c6cb16f
7 changed files with 40 additions and 49 deletions

View File

@@ -29,7 +29,7 @@ pub enum DebounceMode {
/// behavior. Each event kind can have its own mode.
pub struct DebouncedDispatcher {
handler: Arc<dyn HookHandler>,
action_tx: mpsc::Sender<Action>,
_action_tx: mpsc::Sender<Action>,
modes: HashMap<HookEventKind, DebounceMode>,
in_flight: HashMap<HookEventKind, JoinHandle<()>>,
}
@@ -41,7 +41,7 @@ impl DebouncedDispatcher {
) -> Self {
Self {
handler,
action_tx,
_action_tx: action_tx,
modes: HashMap::new(),
in_flight: HashMap::new(),
}
@@ -95,17 +95,9 @@ impl DebouncedDispatcher {
fn fire_now(&self, event: HookEvent) {
let handler = Arc::clone(&self.handler);
let action_tx = self.action_tx.clone();
tokio::spawn(async move {
match handler.handle(event) {
Ok(responses) => {
for resp in responses {
let _ = action_tx.send(Action::ProcessHookResponse(resp)).await;
}
}
Err(e) => {
tracing::warn!(error = %e, "hook handler error");
}
if let Err(e) = handler.handle(event) {
tracing::warn!(error = %e, "hook handler error");
}
});
}
@@ -117,18 +109,10 @@ impl DebouncedDispatcher {
}
let handler = Arc::clone(&self.handler);
let action_tx = self.action_tx.clone();
let handle = tokio::spawn(async move {
tokio::time::sleep(delay).await;
match handler.handle(event) {
Ok(responses) => {
for resp in responses {
let _ = action_tx.send(Action::ProcessHookResponse(resp)).await;
}
}
Err(e) => {
tracing::warn!(error = %e, "hook handler error");
}
if let Err(e) = handler.handle(event) {
tracing::warn!(error = %e, "hook handler error");
}
});
@@ -165,11 +149,11 @@ mod tests {
}
impl HookHandler for RecordingHandler {
fn handle(&self, event: HookEvent) -> Result<Vec<HookResponse>, PiklError> {
fn handle(&self, event: HookEvent) -> Result<(), PiklError> {
if let Ok(mut events) = self.events.lock() {
events.push(event.kind());
}
Ok(vec![])
Ok(())
}
}