fix function args and add test

This commit is contained in:
dave 2024-06-16 11:35:01 -07:00
parent b1de6c9246
commit fb4f17791e
2 changed files with 33 additions and 2 deletions

View File

@ -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
View 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")
}
}