mirror of
https://github.com/umputun/reproxy.git
synced 2024-09-11 08:55:25 +03:00
Fix missed file update if consumer of events is busy, e.g. waiting on a lock
This commit is contained in:
parent
5d9283be34
commit
936a0815a0
@ -26,10 +26,12 @@ func (d *File) Events(ctx context.Context) <-chan struct{} {
|
||||
res := make(chan struct{})
|
||||
|
||||
// no need to queue multiple events
|
||||
trySubmit := func(ch chan struct{}) {
|
||||
trySubmit := func(ch chan struct{}) bool {
|
||||
select {
|
||||
case ch <- struct{}{}:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
@ -50,8 +52,9 @@ func (d *File) Events(ctx context.Context) <-chan struct{} {
|
||||
}
|
||||
log.Printf("[DEBUG] file %s changed, %s -> %s", d.FileName,
|
||||
lastModif.Format(time.RFC3339Nano), fi.ModTime().Format(time.RFC3339Nano))
|
||||
lastModif = fi.ModTime()
|
||||
trySubmit(res)
|
||||
if trySubmit(res) {
|
||||
lastModif = fi.ModTime()
|
||||
}
|
||||
}
|
||||
case <-ctx.Done():
|
||||
close(res)
|
||||
|
Loading…
Reference in New Issue
Block a user