libf 2 years ago
parent
commit
74cbebcf6e
1 changed files with 21 additions and 0 deletions
  1. 21 0
      timer/timer_test.go

+ 21 - 0
timer/timer_test.go

@@ -0,0 +1,21 @@
+package timer_test
+
+import (
+	"fmt"
+	"testing"
+	"time"
+)
+
+func TestTimer(t *testing.T) {
+	ch := make(chan interface{}, 1)
+	ch <- time.Now()
+	for {
+		select {
+		case <-ch:
+			fmt.Println(time.Now())
+			time.AfterFunc(1*time.Second, func() {
+				ch <- time.Now()
+			})
+		}
+	}
+}