It is impossible to deconstruct a received value in one line of code:X, Y := <-updates // impossiblebecause it interferes with the optional status returned by the receive operator (http://golang.org/ref/spec#Receive_operator). This also applies to your proposal.
Doesn't "to come up with several more use cases besides just channels" mean the inclusion of tuples into the language as a 1st class value? If it does, it is impossible to decide what "X, Y := <-updates" means because X could be a tuple or the 1st element of the tuple.
This was discussed some time ago on the ML:
https://groups.google.com/forum/?fromgroups=#!topic/golang-nuts/K11-UgsHQQs
i'm think about something like this (post on phone, so
there might be errors):
type tuple struct { a, b, c int }
func (t *tuple) get() (a, b, c int) {
if t != nil {
return t.a, t.b, t.c
}
return
}
ch := make(chan *tuple)
// to send
ch <- &tuple{1, 2, 3}
// receive
a, b, c := (<-ch).get()
in this way, closed channel is automatically translated
to receiving all zeros.
[...]
Mutually exclusive multiple values as in the common val, err := f()
construct in go. In which case multiple channels with a select is more
than adequate and in some cases superior to a multiple value channel.
Mutually inclusive multiple values. The struct case seems a natural
fit for this as well since the values are usually meant to be bundled
anyway.
Is there a use case other than these that you had in mind?
The simplest is still a command struct with a message code and an interface, which is switch type-asserted on the receiving side. (Or a type switch, but this involves reflection overhead)
Slightly more complicated would be a serializer/deserializer combination like gob(or a custom). This has the advantage of being extendable over a network later.
Slightly more flexible (and less thread safe) would be a function pointer channel, over which you pass closures or methods. This is my favourite as it can be highly modular and extensible, but you have to watch out for shared memory access (try to close over channels). It gets fun when the worker passes function pointers back.
There are many other ways, but it really depends on what the performance constraints/demands of your program are.
-Simon Watt