Created
April 24, 2017 08:37
-
-
Save oyakata/62a2122dd8d0c065b7186aa06395d1eb to your computer and use it in GitHub Desktop.
time.Tickerを利用するモジュールのテストはどうしたら良い?Stop()の例
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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