Skip to content

Instantly share code, notes, and snippets.

@kisielk
Created March 15, 2013 20:43
Show Gist options
  • Save kisielk/5172973 to your computer and use it in GitHub Desktop.
Save kisielk/5172973 to your computer and use it in GitHub Desktop.
Timer, why u no fire?
var (
Forever = time.Duration(math.MaxInt64)
Debounce = time.Second
)
// Other unrelated things here
for {
t := time.NewTimer(Forever)
select {
case event := <-watcher.Event:
if event.IsCreate() && strings.HasSuffix(event.Name, ".go") {
watcher.Watch(event.Name)
}
// We don't watch IsDelete() right now because editors like to do weird things
log.Println(event)
log.Println("timer reset", t.Reset(Debounce))
case <-t.C:
log.Println("timer expired", t.Reset(Forever))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment