Andrew
Although I couldn't find any topic with the google groups search, I feel like this has been discussed before, if not recently.I think it would be of great convenience if a goroutine launch returned a channel that sent something of the function's return type.That is,func foo(...) X { ... }...var ch chan X = go foo(...)equiv tofunc gofoo(...) (ch chan X) {ch = make(chan X)go func() {ch <- foo()}()return}...var ch chan X = gofoo()
Of course, for multi-returns (which must be named):func foo(...) (x X, y Y) { ... }...var ch chan struct {x X; y Y} = go foo()equiv tofunc gofoo(...) (ch chan struct {x X; y Y}) {ch = make(chan struct {x X; y Y})go func() {var rval struct {x X; y Y}rval.x, rval.y = foo()ch <- rval}()return}...var ch chan X = gofoo()
For functions with no return values it would be an empty struct.func foo(...) { ... }var ch chan struct{} = go foo()
As I said, this would only be a convenience, but people very often need to write the same infrastructure (with minor name changing) to wait for completion of goroutines. The following code is much nicer than wrapping the called functions and setting up a wait infrastructure.ch1 := go foo1()ch2 := go foo2()ch3 := go foo3()<-ch1<-ch2<-ch3