咖啡伴侶

          呆在上海
          posts - 163, comments - 156, trackbacks - 0, articles - 2

          golang chan 超時

          Posted on 2013-12-24 13:03 oathleo 閱讀(7291) 評論(0)  編輯  收藏
          package main

          import (
              "fmt"
              "time"
          )

          var ch chan int = make(chan int, 1)

          func main() {
              go aaa()

              select {
              case <-ch: //拿到鎖
                  fmt.Println("call")
              case <-time.After(5 * time.Second): //超時5s
                  fmt.Println("5 sec call")
              }
          }

          func aaa() {
              time.Sleep(time.Second * 3)
              ch <- 1
          }

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 莆田市| 阳东县| 稻城县| 新宾| 内乡县| 浪卡子县| 日喀则市| 辉南县| 武邑县| 城市| 泰宁县| 安陆市| 达拉特旗| 邯郸市| 广安市| 永丰县| 健康| 英德市| 如东县| 鄯善县| 丰顺县| 务川| 安丘市| 通渭县| 稷山县| 望奎县| 合阳县| 孟连| 榆树市| 衡阳县| 西吉县| 大城县| 界首市| 新野县| 浙江省| 讷河市| 西乌| 田阳县| 靖安县| 峨山| 冷水江市|