golang channel basic
2015-10-16 10:09
441 查看
package mainimport ( "fmt" "math/rand" "time")func main() { rand.Seed(time.Now().UnixNano()) q := make(chan string) words := []string{"Enjoy", "Go", "Coding", "Patrick"} t := time.Now() for _, w := range words { // passing w to each goroutine to avoid repeating the same! Try not to. go func(w string) { time.Sleep(time.Duration(rand.Int63n(1e9))) q <- w }(w) } for i := 0; i < len(words); i++ { // reading from channel q fmt.Printf("%q\t\t", <-q) fmt.Println("Created in:", time.Now().Sub(t)) }}
sleep 范围是0 - 1e9(1000000000)
+5level:2exp:5/50
相关文章推荐
- BAPI_GOODSMVT_CREATE移库操作(WMS TO SAP)
- golang level
- Go小计 - 可见性规则
- golang exec Command
- golang time and duration
- HOTPOWER.【专注游戏界面外包】/接游戏界面外包/logo外包/icon
- Django初试
- lightoj 1152 - Hiding Gold 【奇偶建二分图 求最大匹配】
- go-lang开发环境搭建
- Django 学习笔记
- algorithm@ dijkstra algorithm & prim algorithm
- OCdemo-07 CateGory 类目
- django入门(一)
- 借助 Django 的 smart_str 和 smart_unicode 进行编码转换(转)
- hdu 3966 Aragorn's Story 树链剖分
- google guava
- IDEA14中安装go语言插件
- Go学习笔记:xml库的使用
- 如果访问google
- POJ 1003 Hangover