Skip to content

Instantly share code, notes, and snippets.

@oyakata
Created April 24, 2017 08:37
Show Gist options
  • Save oyakata/62a2122dd8d0c065b7186aa06395d1eb to your computer and use it in GitHub Desktop.
Save oyakata/62a2122dd8d0c065b7186aa06395d1eb to your computer and use it in GitHub Desktop.
time.Tickerを利用するモジュールのテストはどうしたら良い?Stop()の例
package main
import (
"fmt"
"time"
)
func hello(tic *time.Ticker) {
for {
select {
case <-tic.C:
fmt.Println("Hello, world.")
}
}
}
func main() {
t := time.NewTicker(100 * time.Millisecond)
go hello(t)
time.Sleep(200 * time.Millisecond)
t.Stop()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment