fix function args and add test
This commit is contained in:
parent
b1de6c9246
commit
fb4f17791e
@ -6,12 +6,12 @@ import (
|
||||
|
||||
type CallTicker struct {
|
||||
manualTrigger chan interface{}
|
||||
function func(...interface{}) interface{}
|
||||
function func()
|
||||
ticker *time.Ticker
|
||||
duration time.Duration
|
||||
}
|
||||
|
||||
func NewCallTicker(d time.Duration, function func(...interface{}) interface{}) *CallTicker {
|
||||
func NewCallTicker(d time.Duration, function func()) *CallTicker {
|
||||
ticker := &CallTicker{
|
||||
manualTrigger: make(chan interface{}),
|
||||
function: function,
|
||||
|
31
ticker_test.go
Normal file
31
ticker_test.go
Normal file
@ -0,0 +1,31 @@
|
||||
package callticker
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestTicker(t *testing.T) {
|
||||
num := 0
|
||||
|
||||
incr := func() {
|
||||
num += 1
|
||||
}
|
||||
|
||||
ticker := NewCallTicker(time.Millisecond*50, incr)
|
||||
go ticker.Run()
|
||||
|
||||
time.Sleep(time.Millisecond * 275)
|
||||
|
||||
if num != 5 {
|
||||
t.Errorf("expected 5 calls by now")
|
||||
}
|
||||
|
||||
ticker.Stop()
|
||||
|
||||
time.Sleep(time.Millisecond * 100)
|
||||
|
||||
if num != 5 {
|
||||
t.Errorf("expected calls to stop")
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user