Skip to content

Commit 2bddc86

Browse files
committed
bin/watch: Add debounce for batched events
1 parent 631afe8 commit 2bddc86

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

bin/watch

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python3
22
import os
33
import subprocess
4-
from datetime import datetime
4+
import time
55
from pathlib import Path
66
from time import sleep
77

@@ -24,7 +24,7 @@ def watch_for_changes():
2424
class MyHandler(FileSystemEventHandler):
2525
def __init__(self):
2626
super().__init__()
27-
self.last_build = datetime.now()
27+
self.last_build = time.time()
2828

2929
def on_modified(self, event: FileSystemEvent):
3030
cwd = os.getcwd()
@@ -50,8 +50,12 @@ def watch_for_changes():
5050
if str(file_path).startswith(ignored_path):
5151
return
5252

53+
if self.last_build and time.time() - self.last_build < 0.5:
54+
return
55+
5356
build_docs()
5457
refresh_assets()
58+
self.last_build = time.time()
5559

5660
event_handler = MyHandler()
5761
observer = Observer()

0 commit comments

Comments
 (0)