What does `(<-chan Delivery)(deliveries)` do?

huangapple go评论67阅读模式
英文:

What does `(<-chan Delivery)(deliveries)` do?

问题

我找到了这行代码:

return (<-chan Delivery)(deliveries), nil

它的作用是什么?为什么有双括号?

英文:

I found this line:

return (&lt;-chan Delivery)(deliveries), nil

https://github.com/streadway/amqp/blob/master/channel.go#L1089

What does it do? Why the double parentheses?

答案1

得分: 9

这是一个类型转换。在你的情况下,它将chan Delivery(双向的Delivery值通道)转换为<-chan Delivery(只接收Delivery值的通道)。

英文:

It's a type conversion. In your case, it converts chan Delivery (two-way channel of Delivery values) to &lt;-chan Delivery (receive-only channel of Delivery values).

答案2

得分: 4

这是一个类型转换。将deliveries转换为只读通道。

英文:

It is a type conversion. Returns deliveries as a read-only channel.

答案3

得分: 4

这是从双向通道转换为只发送通道的类型转换,如果你提供它,可以省略。转换将隐式完成。

英文:

Its a type conversion from two-way channel to send-only channel and in case you provide it can be omitted. Conversion would be done implicitly.

huangapple
  • 本文由 发表于 2015年1月21日 20:18:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/28067076.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定