// sendOnlyIfEmpty sends on a bool channel only if the channel has no
// backlog to be read by other goroutines. This concurrency pattern
// can be used to notify other goroutines if and only if they are
// looking for it (i.e., subsequent notifications can be compressed
// into one).
func sendOnlyIfEmpty(ch chan bool) {
select {
case ch <- true:
default:
}
}
sendOnlyIfEmpty will not send true until the recevier of fc.Deleted is ready. And the receiver comes to be ready only when io.EOF appears. That means when EOF comes, the event of deleted has passed away. waitForChanges() can not do anything but wait.
so, notifyDeleted should wait (drop sendOnlyIfEmpty). it is different with modified event.
By the way, the name of sendOnlyIfEmpty makes confused.
it will stop when tail the log which is deleted periodically and a new one created. I think it cased by the code follow:
func (fc *FileChanges) NotifyDeleted() { sendOnlyIfEmpty(fc.Deleted) }
// sendOnlyIfEmpty sends on a bool channel only if the channel has no // backlog to be read by other goroutines. This concurrency pattern // can be used to notify other goroutines if and only if they are // looking for it (i.e., subsequent notifications can be compressed // into one). func sendOnlyIfEmpty(ch chan bool) { select { case ch <- true: default: } }
sendOnlyIfEmpty will not send true until the recevier of fc.Deleted is ready. And the receiver comes to be ready only when io.EOF appears. That means when EOF comes, the event of deleted has passed away. waitForChanges() can not do anything but wait.
so, notifyDeleted should wait (drop sendOnlyIfEmpty). it is different with modified event. By the way, the name of sendOnlyIfEmpty makes confused.