|
Si guy |
at Sep 4, 2012 at 9:06 pm
|
⇧ |
| |
When you have to use a goroutine inner of a function (to be used by
another function), which is the "better" way to use?
1. Indicate that the function has to be run using a goroutine, or
2. write directly the code inner of "go func(){...}()"
It depends really. (opinion to follow)
I like to use option 1 for launching threads that assist the current task
and can be initialized in one or two lines, eg:
result := make(chan int)
go docalculations(result)
And option 2 for launching self hosted sub-modules that require extensive
initialization eg:
LaunchHTTPServer() // Launch the HTTP interface
Generally go for maximum readability I think, ask "is this goroutine part
of what I'm doing here? or am I launching another part of the program? Will
the initialization of this goroutine clutter the current function too
much?". That sort of thing.
-Simon Watt