咖啡伴侶

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

          golang chan 超時

          Posted on 2013-12-24 13:03 oathleo 閱讀(7303) 評論(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
          }

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


          網(wǎng)站導航:
           
          主站蜘蛛池模板: 泰宁县| 邹城市| 仁布县| 应用必备| 理塘县| 徐州市| 汶川县| 邢台市| 水城县| 商洛市| 屯门区| 城固县| 衡水市| 凤山市| 旬邑县| 天峨县| 新化县| 赣榆县| 平顺县| 彰化县| 大足县| 贵溪市| 塘沽区| 钟山县| 临江市| 合江县| 阜平县| 隆林| 西林县| 申扎县| 上思县| 达拉特旗| 黄龙县| 土默特左旗| 永寿县| 鄂托克前旗| 石阡县| 会宁县| 拜城县| 探索| 高唐县|