proper string formatting for txs

This commit is contained in:
Jae Kwon
2015-01-16 00:31:34 -08:00
parent b1be787987
commit 3f159dab69
8 changed files with 63 additions and 8 deletions
+6 -2
View File
@@ -7,16 +7,17 @@ RepeatTimer repeatedly sends a struct{}{} to .Ch after each "dur" period.
It's good for keeping connections alive.
*/
type RepeatTimer struct {
Name string
Ch chan struct{}
quit chan struct{}
dur time.Duration
timer *time.Timer
}
func NewRepeatTimer(dur time.Duration) *RepeatTimer {
func NewRepeatTimer(name string, dur time.Duration) *RepeatTimer {
var ch = make(chan struct{})
var quit = make(chan struct{})
var t = &RepeatTimer{Ch: ch, dur: dur, quit: quit}
var t = &RepeatTimer{Name: name, Ch: ch, dur: dur, quit: quit}
t.timer = time.AfterFunc(dur, t.fireRoutine)
return t
}
@@ -26,6 +27,9 @@ func (t *RepeatTimer) fireRoutine() {
case t.Ch <- struct{}{}:
t.timer.Reset(t.dur)
case <-t.quit:
// do nothing
default:
t.timer.Reset(t.dur)
}
}
+6 -2
View File
@@ -12,6 +12,7 @@ If a long continuous burst of .Set() calls happens, ThrottleTimer fires
at most once every "dur".
*/
type ThrottleTimer struct {
Name string
Ch chan struct{}
quit chan struct{}
dur time.Duration
@@ -19,10 +20,10 @@ type ThrottleTimer struct {
isSet uint32
}
func NewThrottleTimer(dur time.Duration) *ThrottleTimer {
func NewThrottleTimer(name string, dur time.Duration) *ThrottleTimer {
var ch = make(chan struct{})
var quit = make(chan struct{})
var t = &ThrottleTimer{Ch: ch, dur: dur, quit: quit}
var t = &ThrottleTimer{Name: name, Ch: ch, dur: dur, quit: quit}
t.timer = time.AfterFunc(dur, t.fireRoutine)
t.timer.Stop()
return t
@@ -33,6 +34,9 @@ func (t *ThrottleTimer) fireRoutine() {
case t.Ch <- struct{}{}:
atomic.StoreUint32(&t.isSet, 0)
case <-t.quit:
// do nothing
default:
t.timer.Reset(t.dur)
}
}