How to understand "<-chan" in declaration?

427 views
Skip to first unread message

Nan Xiao

unread,
Aug 26, 2015, 5:45:47 AM8/26/15
to golang-nuts
Hi all,

When reading runner code in Go in Action, I find the definition of Runner:

type Runner struct {
// interrupt channel reports a signal from the
// operating system.
interrupt chan os.Signal

// complete channel reports that processing is done.
complete chan error

// timeout reports that time has run out.
timeout <-chan time.Time

// tasks holds a set of functions that are executed
// synchronously in index order.
tasks []func(int)
}

How can I understand the "<-chan " in  timeout member declaration?

Thanks in advance!

Best Regards
Nan Xiao

Axel Wagner

unread,
Aug 26, 2015, 5:57:49 AM8/26/15
to Nan Xiao, golang-nuts
Hi,

http://golang.org/ref/spec#Channel_types

The arrow gives the direction, so <-chan Foo means it's a read-only
channel, and chan<- Foo means it's a write-only channel (the arrow
points towards or out of the chan).

Best,

Axel

Nan Xiao <xn21...@163.com> writes:

> Hi all,
>
> When reading runner
> <https://github.com/goinaction/code/blob/master/chapter7/patterns/runner/runner.go> code
> in *Go in Action*, I find the definition of Runner:
> --
> You received this message because you are subscribed to the Google Groups "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Nan Xiao

unread,
Aug 26, 2015, 5:59:45 AM8/26/15
to Axel Wagner, Nan Xiao, golang-nuts
Hi Axel,

Got it! Thanks very much!


Best Regards
Nan Xiao

You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/ul_K7S3EtOk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.

gugl.z...@gmail.com

unread,
Aug 26, 2015, 9:44:21 AM8/26/15
to golang-nuts
Reply all
Reply to author
Forward
0 new messages