咖啡伴侶

          呆在上海
          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
          }

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


          網站導航:
           
          主站蜘蛛池模板: 柳州市| 上饶市| 灵川县| 南安市| 孟连| 庆阳市| 锦州市| 云霄县| 新安县| 阜新市| 涟水县| 永和县| 台东县| 临高县| 调兵山市| 拉萨市| 衡南县| 娱乐| 威海市| 论坛| 钟祥市| 澄城县| 奎屯市| 梨树县| 广水市| 耒阳市| 温宿县| 吉木萨尔县| 定州市| 行唐县| 鄂尔多斯市| 胶南市| 成都市| 扶沟县| 凭祥市| 厦门市| 冀州市| 阳西县| 青田县| 介休市| 泾阳县|