mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-26 05:30:54 +03:00
gofmt all go code
This commit is contained in:
parent
ff9f6e1b2a
commit
6dd2e9a49a
14 changed files with 2013 additions and 2013 deletions
|
@ -1,56 +1,56 @@
|
|||
package watcher
|
||||
|
||||
import (
|
||||
"github.com/howeyc/fsnotify"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Batcher struct {
|
||||
*fsnotify.Watcher
|
||||
interval time.Duration
|
||||
done chan struct{}
|
||||
|
||||
Event chan []*fsnotify.FileEvent // Events are returned on this channel
|
||||
}
|
||||
|
||||
func New(interval time.Duration) (*Batcher, error) {
|
||||
watcher, err := fsnotify.NewWatcher()
|
||||
|
||||
batcher := &Batcher{}
|
||||
batcher.Watcher = watcher
|
||||
batcher.interval = interval
|
||||
batcher.done = make(chan struct{}, 1)
|
||||
batcher.Event = make(chan []*fsnotify.FileEvent, 1)
|
||||
|
||||
if err == nil {
|
||||
go batcher.run()
|
||||
}
|
||||
|
||||
return batcher, err
|
||||
}
|
||||
|
||||
func (b *Batcher) run() {
|
||||
tick := time.Tick(b.interval)
|
||||
evs := make([]*fsnotify.FileEvent, 0)
|
||||
OuterLoop:
|
||||
for {
|
||||
select {
|
||||
case ev := <-b.Watcher.Event:
|
||||
evs = append(evs, ev)
|
||||
case <-tick:
|
||||
if len(evs) == 0 {
|
||||
continue
|
||||
}
|
||||
b.Event <- evs
|
||||
evs = make([]*fsnotify.FileEvent, 0)
|
||||
case <-b.done:
|
||||
break OuterLoop
|
||||
}
|
||||
}
|
||||
close(b.done)
|
||||
}
|
||||
|
||||
func (b *Batcher) Close() {
|
||||
b.done <- struct{}{}
|
||||
b.Watcher.Close()
|
||||
}
|
||||
package watcher
|
||||
|
||||
import (
|
||||
"github.com/howeyc/fsnotify"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Batcher struct {
|
||||
*fsnotify.Watcher
|
||||
interval time.Duration
|
||||
done chan struct{}
|
||||
|
||||
Event chan []*fsnotify.FileEvent // Events are returned on this channel
|
||||
}
|
||||
|
||||
func New(interval time.Duration) (*Batcher, error) {
|
||||
watcher, err := fsnotify.NewWatcher()
|
||||
|
||||
batcher := &Batcher{}
|
||||
batcher.Watcher = watcher
|
||||
batcher.interval = interval
|
||||
batcher.done = make(chan struct{}, 1)
|
||||
batcher.Event = make(chan []*fsnotify.FileEvent, 1)
|
||||
|
||||
if err == nil {
|
||||
go batcher.run()
|
||||
}
|
||||
|
||||
return batcher, err
|
||||
}
|
||||
|
||||
func (b *Batcher) run() {
|
||||
tick := time.Tick(b.interval)
|
||||
evs := make([]*fsnotify.FileEvent, 0)
|
||||
OuterLoop:
|
||||
for {
|
||||
select {
|
||||
case ev := <-b.Watcher.Event:
|
||||
evs = append(evs, ev)
|
||||
case <-tick:
|
||||
if len(evs) == 0 {
|
||||
continue
|
||||
}
|
||||
b.Event <- evs
|
||||
evs = make([]*fsnotify.FileEvent, 0)
|
||||
case <-b.done:
|
||||
break OuterLoop
|
||||
}
|
||||
}
|
||||
close(b.done)
|
||||
}
|
||||
|
||||
func (b *Batcher) Close() {
|
||||
b.done <- struct{}{}
|
||||
b.Watcher.Close()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue