開発環境
- macOS High Sierra - Apple (OS)
- Emacs (Text Editor)
- Go (プログラミング言語)
Introducing Go: Build Reliable, Scalable Programs (Caleb Doxsey (著)、O'Reilly Media)のChapter 10.(Concurrency)、Exercises(No. 1879)2.を取り組んでみる。
コード(Emacs)
package main
import (
"fmt"
"time"
)
func Sleep(d time.Duration) {
select {
case <-time.After(d):
}
}
func main() {
xs := []time.Duration{1, 5, 10}
for _, x := range xs {
fmt.Println(time.Now().Second())
Sleep(time.Second * x)
fmt.Println(time.Now().Second())
fmt.Println()
}
}
入出力結果(Terminal)
$ go run sample2.go 5 6 6 11 11 21 $
0 コメント:
コメントを投稿