What happens to return value from goroutine

前端 未结 5 1745
心在旅途
心在旅途 2021-01-12 00:45

Could someone please give clarification values returned from the goroutine. Does the returned value from the goroutine is getting stored on stake.

example :

5条回答
  •  清歌不尽
    2021-01-12 01:35

    Quoting from the Go Language specification: Go statements:

    If the function has any return values, they are discarded when the function completes.

    So it is allowed to execute functions with return values as goroutines - there is nothing wrong with it, and the specification clearly states that their return values are simply discarded, it will not cause any error but you won't get it in the usually way (as you would by directly calling the function).

提交回复
热议问题