GetChan returns a chan of deduplicated [fsnotify.Event]. [fsnotify.Chmod] operations will be skipped.
()
| 23 | // |
| 24 | // [fsnotify.Chmod] operations will be skipped. |
| 25 | func (d *Deduper) GetChan() <-chan fsnotify.Event { |
| 26 | channel := make(chan fsnotify.Event) |
| 27 | |
| 28 | go func() { |
| 29 | timers := make(map[string]*time.Timer) |
| 30 | for { |
| 31 | event, ok := <-d.w.Events |
| 32 | switch { |
| 33 | case !ok: |
| 34 | return |
| 35 | case event.Has(fsnotify.Chmod): |
| 36 | continue |
| 37 | } |
| 38 | |
| 39 | timer, ok := timers[event.String()] |
| 40 | if !ok { |
| 41 | timer = time.AfterFunc(math.MaxInt64, func() { channel <- event }) |
| 42 | timer.Stop() |
| 43 | timers[event.String()] = timer |
| 44 | } |
| 45 | |
| 46 | timer.Reset(d.waitTime) |
| 47 | } |
| 48 | }() |
| 49 | |
| 50 | return channel |
| 51 | } |