登录
首页 >  Golang >  Go问答

Go 中函数的通道返回类型中的 `<-` 是什么意思?

来源:stackoverflow

时间:2024-04-06 11:39:45 343浏览 收藏

哈喽!今天心血来潮给大家带来了《Go 中函数的通道返回类型中的 `,想必大家应该对Golang都不陌生吧,那么阅读本文就都不会很困难,以下内容主要涉及到,若是你正在学习Golang,千万别错过这篇文章~希望能帮助到你!

问题内容

我想知道 go 中函数的通道返回类型中的 <- 是什么意思。事实上,类型 t 的通道被写为 chan t 并使用 make(chan t, n) 创建,那么“<-”在 time.after 的返回类型中意味着什么?

go doc time.After
package time // import "time"

func After(d Duration) <-chan Time
    After waits for the duration to elapse and then sends the current time on
    the returned channel. It is equivalent to NewTimer(d).C. The underlying
    Timer is not recovered by the garbage collector until the timer fires. If
    efficiency is a concern, use NewTimer instead and call Timer.Stop if the
    timer is no longer needed.

奖金

如何从 go doc 中看到 time.after 是异步的,并且在持续时间过去之前不会阻塞?


解决方案


<-chan time 表示 After 返回时间值的只读通道。

chan time 是一个读写通道。

奖金:

你是对的。文档不够清晰。你必须从签名中猜测出来。

您也许可以对 After 的作用提出更好、更明确的描述。 Go 是一个开源项目,这将是一个做出贡献的机会。

今天带大家了解了的相关知识,希望对你有所帮助;关于Golang的技术知识我们会一点点深入介绍,欢迎大家关注golang学习网公众号,一起学习编程~

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>