Go statements

未匹配的标注

go 语句作为一个独立的并发控制线程(或者称作 goroutine)在同一地址空间内开始执行函数调用。

GoStmt = "go" Expression .

表达式必须是函数或方法调用;不能用括号括起来。内置函数的调用受表达式语句的限制。

函数值和参数在调用 goroutine 中通常像其他方式一样进行估值。但与常规调用不同,程序执行不等待被调用函数完成。相反,该函数开始在新的 goroutine 中独立执行。当函数终止时,其 goroutine 也终止。如果函数具有任何返回值,则在函数完成时将其丢弃。

go Server()
go func(ch chan<- bool) { for { sleep(10); ch <- true }} (c)

The function value and parameters are evaluated as usual in the calling goroutine, but unlike with a regular call, program execution does not wait for the invoked function to complete. Instead, the function begins executing independently in a new goroutine. When the function terminates, its goroutine also terminates. If the function has any return values, they are discarded when the function completes.

go Server()
go func(ch chan<- bool) { for { sleep(10); ch <- true }} (c)

本文章首发在 LearnKu.com 网站上。

本译文仅用于学习和交流目的,转载请务必注明文章译者、出处、和本文链接
我们的翻译工作遵照 CC 协议,如果我们的工作有侵犯到您的权益,请及时联系我们。

原文地址:https://learnku.com/docs/go-specificatio...

译文地址:https://learnku.com/docs/go-specificatio...

上一篇 下一篇
贡献者:1
讨论数量: 0
发起讨论 只看当前版本


暂无话题~