@ -17,6 +17,7 @@ import (
"strings"
"strings"
"sync"
"sync"
"sync/atomic"
"sync/atomic"
"time"
fsnotify "gopkg.in/fsnotify.v1"
fsnotify "gopkg.in/fsnotify.v1"
)
)
@ -67,7 +68,6 @@ func watchFS(ch chan struct{}, w *fsnotify.Watcher) {
select {
select {
case e := <- w . Events :
case e := <- w . Events :
if filter ( e ) {
if filter ( e ) {
wg . Add ( 1 )
fmt . Printf ( "Noticed change to %s, re-generating spec\n" , e . Name )
fmt . Printf ( "Noticed change to %s, re-generating spec\n" , e . Name )
ch <- struct { } { }
ch <- struct { } { }
}
}
@ -98,6 +98,11 @@ func filter(e fsnotify.Event) bool {
return false
return false
}
}
// Ignore the .git directory - It's very noisy
if strings . Contains ( e . Name , "/.git/" ) {
return false
}
// Avoid infinite cycles being caused by writing actual output
// Avoid infinite cycles being caused by writing actual output
if strings . Contains ( e . Name , "/tmp/" ) || strings . Contains ( e . Name , "/gen/" ) {
if strings . Contains ( e . Name , "/tmp/" ) || strings . Contains ( e . Name , "/gen/" ) {
return false
return false
@ -133,9 +138,21 @@ func populateOnce(dir string) {
}
}
func doPopulate ( ch chan struct { } , dir string ) {
func doPopulate ( ch chan struct { } , dir string ) {
for _ = range ch {
var pending int
for {
select {
case <- ch :
if pending == 0 {
wg . Add ( 1 )
}
pending ++
case <- time . After ( 10 * time . Millisecond ) :
if pending > 0 {
pending = 0
populateOnce ( dir )
populateOnce ( dir )
}
}
}
}
}
}
func exists ( path string ) bool {
func exists ( path string ) bool {