podman

Форк
0
37 строк · 1.0 Кб
1
// Copyright (c) 2019 FOSS contributors of https://github.com/nxadm/tail
2
package watch
3

4
type FileChanges struct {
5
	Modified  chan bool // Channel to get notified of modifications
6
	Truncated chan bool // Channel to get notified of truncations
7
	Deleted   chan bool // Channel to get notified of deletions/renames
8
}
9

10
func NewFileChanges() *FileChanges {
11
	return &FileChanges{
12
		make(chan bool, 1), make(chan bool, 1), make(chan bool, 1)}
13
}
14

15
func (fc *FileChanges) NotifyModified() {
16
	sendOnlyIfEmpty(fc.Modified)
17
}
18

19
func (fc *FileChanges) NotifyTruncated() {
20
	sendOnlyIfEmpty(fc.Truncated)
21
}
22

23
func (fc *FileChanges) NotifyDeleted() {
24
	sendOnlyIfEmpty(fc.Deleted)
25
}
26

27
// sendOnlyIfEmpty sends on a bool channel only if the channel has no
28
// backlog to be read by other goroutines. This concurrency pattern
29
// can be used to notify other goroutines if and only if they are
30
// looking for it (i.e., subsequent notifications can be compressed
31
// into one).
32
func sendOnlyIfEmpty(ch chan bool) {
33
	select {
34
	case ch <- true:
35
	default:
36
	}
37
}
38

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.