← 返回刚才阅读的位置

知识卡片

普通读书笔记卡 · 4545.g.2.a

协程启动不等待函数返回

理解等级:中级

在函数调用前加go会启动独立执行的goroutine,当前调用者继续向下运行。匿名函数也可这样启动,但依然需要实际调用括号。启动容易不代表生命周期自动受控:若后续逻辑依赖结果,应另用通信或同步等待,不能假定先启动的一定先完成。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • Go Language Foundations · 查看原书依据

      Any function call prepended with go keyword will run as usual, but the caller can proceed uninterrupted rather wait for the function to return. Under the hood, the function is executed as lightweight, concurrently executing processes called a goroutine. The syntax is strikingly simple: a function foo, which may be executed sequentially as foo(), may

    参考来源

    - 位置:《Cloud Native Go》第03章《Go Language Foundations》(来源项目book-sources;源文件:extracted/Cloud Native Go (Matthew A. Titmus)/_epub-src/OEBPS/ch03.xhtml) - 结论依据:在函数调用前加go会启动独立执行的goroutine,当前调用者继续向下运行。原文相应定义、示例或限制为此结论提供依据;补充纠错与版本边界在正文就近标明。 - 原始内容:Any function call prepended with go keyword will run as usual, but the caller can proceed uninterrupted rather wait for the function to return. Under the hood, the function is executed as lightweight, concurrently executing processes called a goroutine. The syntax is strikingly simple: a function foo, which may be executed sequentially as foo(), may