2016年2月8日月曜日

開発環境

  • OS X El Capitan - Apple (OS)
  • Emacs (Text Editor)
  • Go (version go1.5.3 darwin/amd64) (プログラミング言語)

Introducing Go (Caleb Doxsey (著)、O'Reilly Media)のChapter 10.(Concurrency)、Exercises 1-3.(No. 2095)を取り組んでみる。

Exercises 1-3.(No. 2095)

コード(Emacs)

package main

import (
 "fmt"
 "time"
)

func Sleep(d time.Duration) {
 <- time.After(d)
}

func main() {
 fmt.Println("2.")
 fmt.Println("before")
 Sleep(time.Second * 5)
 fmt.Println("after")
}

入出力結果(Terminal)

$ time go run main.go
2.
before
after

real 0m6.208s
user 0m1.346s
sys 0m0.248s
$

0 コメント:

コメントを投稿