doutang7707 2012-09-17 01:48
浏览 133
已采纳

Go-Python的“ pass”等效于什么?

I have a default cause in a select statement that I want to do nothing, just continue, but leaving the line blank stops anything in the statement from happening

        select {
        case quit_status := <-quit:
            if quit_status == true {
                fmt.Printf("********************* GOROUTINE [%d] Received QUIT MSG
", id)
                return
            }
        default:
            fmt.Printf("GOROUTINE [%d] step: %d, NO QUIT MSG
", id, i)
        }
  • 写回答

1条回答 默认 最新

  • duanming7961 2012-09-17 02:00
    关注

    The default case in a select statement is intended to provide non-blocking I/O for channel reads and writes. The code in the default case is executed whenever none of the channels in any of the cases are ready to be read/written to.

    So in your case, the default block is executed if the quit channel has nothing to say. You can simply remove the default case and it will block on the quit_status := <-quit case until a value is available in quit.. which is probably what you are after in this instance.

    If you want to immediately continue executing code after the select statement, you should run this select statement in a separate goroutine:

    go func() {
        select {
        case quit_status := <-quit:
            ...
    
        }
    }()
    
    // Execution continues here immediately.
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)