fix(clients): останавливать горячую перезагрузку базы по контексту

This commit is contained in:
samosvalishe committed 2026-09-21 13:43:01 +03:00
1 parent fd5c4f92a5
commit b621182ce4
2 files changed
+10 -4

No files matched your search

+9 -3
View File
@@ -1,6 +1,7 @@
package clientsdb
import (
"context"
"encoding/json"
"fmt"
"io"
@@ -41,12 +42,17 @@ func New(path string) (*DB, error) {
return db, nil
}
func (db *DB) StartHotReload(interval time.Duration) {
func (db *DB) StartHotReload(ctx context.Context, interval time.Duration) {
go func() {
ticker := time.NewTicker(interval)
defer ticker.Stop()
for range ticker.C {
db.loadIfModified()
for {
select {
case <-ctx.Done():
return
case <-ticker.C:
db.loadIfModified()
}
}
}()
}