← 返回刚才阅读的位置

知识卡片

普通读书笔记卡 · 4545.g.3.d

选择语句等待可用通信

理解等级:中级

select在若干发送或接收中选择可执行分支;没有就绪分支且无default时等待,有default则立即走默认分支。多个就绪分支不保证业务优先级;关闭通道持续可读,处理后须避免它成为热循环来源。把定时器通道加入选择能限制等待,但不自动取消其他正在进行的工作。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • Go Language Foundations · 查看原书依据

      If no cases are ready, the default statements will be executed. If there’s no default, then the select will block until one of its cases is ready, at which point it performs the associated communication and executes the associated statements. If multiple cases are ready, select will execute one at random. Gotcha! When using select,

    参考来源

    - 位置:《Cloud Native Go》第03章《Go Language Foundations》(来源项目book-sources;源文件:extracted/Cloud Native Go (Matthew A. Titmus)/_epub-src/OEBPS/ch03.xhtml) - 结论依据:select在若干发送或接收中选择可执行分支;没有就绪分支且无default时等待,有default则立即走默认分支。原文相应定义、示例或限制为此结论提供依据;补充纠错与版本边界在正文就近标明。 - 原始内容:If no cases are ready, the default statements will be executed. If there’s no default, then the select will block until one of its cases is ready, at which point it performs the associated communication and executes the associated statements. If multiple cases are ready, select will execute one at random. Gotcha! When using select,