Refactor etcd into object and add exit timers
This refactors my etcd use into a struct (object) wrapper, which makes it easier to add an exit on converged timer.
This commit is contained in:
10
misc.go
10
misc.go
@@ -23,6 +23,7 @@ import (
|
||||
"encoding/gob"
|
||||
"path"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Similar to the GNU dirname command
|
||||
@@ -110,3 +111,12 @@ func B64ToObj(str string, obj interface{}) bool {
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// special version of time.After that blocks when given a negative integer
|
||||
// when used in a case statement, the timer restarts on each select call to it
|
||||
func TimeAfterOrBlock(t int) <-chan time.Time {
|
||||
if t < 0 {
|
||||
return make(chan time.Time) // blocks forever
|
||||
}
|
||||
return time.After(time.Duration(t) * time.Second)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user