首页 > 解决方案 > Go中函数的通道返回类型中的`<-`是什么意思?

问题描述

我想知道<-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是异步的并且在持续时间过去之前不会阻塞?

标签: go

解决方案


返回时间值的只读通道的方法<-chan timeAfter

Achan time是一个读写通道。

奖金:

你说的对。文档不够清楚。您必须从签名中猜测它。

您可能会建议对所做的事情进行更好且不那么模棱两可的描述After。Go 是一个开源项目,这将是一个贡献的机会。


推荐阅读