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
}

  

相关文章:

  • 2021-07-13
  • 2021-11-13
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-27
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-07-12
  • 2021-08-20
  • 2022-12-23
  • 2022-12-23
  • 2021-12-26
  • 2022-12-23
相关资源
相似解决方案