FAQ
Hello All,

I need to run set of goroutines with the same behaviour but different
state.

Let i'll try to explain with more details what i need . For example i have
a system written in golang, where i need to handle many user connection in
one time. If i would wrote something like this in erlang i'd create one
process/gen_server registered with name or PID for every user with
different state for each process (username, etc....) and than i'd send
messages to process what i need by it's name or PID.

Are there any patterns or best practices for this in golang? If i need to
have many goroutines with the same behaviour but different state.

Thank you.

--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Tamás Gulácsi at Jun 30, 2014 at 9:24 am
    Pass the state (either as params, or as a struct).

    Several possibilities exist, but I'd create a function which gets the state and returns a chan.

    Inside it shall create a goroutine and the channel. The goroutine could be a method of the state struct.

    The state would be a pointer to a struct, its methods do what needs to be done regarding the state.

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Shawn Milochik at Jun 30, 2014 at 1:44 pm
    This could be a good use for closures. Write a function which takes the
    user info and returns a custom function for that user.

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJun 30, '14 at 7:45a
activeJun 30, '14 at 1:44p
posts3
users3
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase