FAQ
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(){...}()"

Search Discussions

  • 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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedSep 4, '12 at 7:04p
activeSep 4, '12 at 9:06p
posts2
users2
websitegolang.org

2 users in discussion

Si guy: 1 post Archos: 1 post

People

Translate

site design / logo © 2022 Grokbase