Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
spacemanspiff2007 committed Nov 26, 2024
1 parent 45f196f commit 28d0447
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/HABApp/core/files/watcher/file_watcher.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from asyncio import run_coroutine_threadsafe, sleep
from collections.abc import Awaitable, Callable
from pathlib import Path
from time import monotonic
from typing import Any

import HABApp
Expand All @@ -21,7 +20,7 @@ def __init__(self, folder: Path, func: Callable[[list[Path]], Awaitable[Any]], f
self.func = func

self._files: set[Path] = set()
self.last_event: float = 0
self._event_obj: object = object()

@ignore_exception
def file_changed(self, dst: str) -> None:
Expand All @@ -30,14 +29,14 @@ def file_changed(self, dst: str) -> None:

@ignore_exception
async def _event_waiter(self, dst: Path):
self.last_event = ts = monotonic()
self._event_obj = event_obj = object()
self._files.add(dst)

# debounce time
await sleep(DEBOUNCE_TIME)

# check if a new event came
if self.last_event > ts:
if self._event_obj is not event_obj:
return None

# Copy Path so we're done here
Expand Down

0 comments on commit 28d0447

Please sign in to comment.