FAQ
Given the following: http://play.golang.org/p/n2cR28T3DJ
Why is it I can't set the "running" struct member in DefaultController and
have it reflected in the call Running().
I know that I'm receiving a copy of the interface, so I'm assuming that is
the problem. How do you get around this
so you can directly manipulate the concrete type of the interface?

--
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

  • Kevin Malachowski at Aug 13, 2014 at 8:27 pm
    If you make the Start method have a pointer receiver then it will work. The problem is that even though the process method has a pointer receiver, it is working on the copied DefaultController in Start, rather than the one allocated in NewDefaultController.

    Note, though, that even if that is fixed your example has a data race since there is no synchronization between setting the value of running in the processes goroutine and reading the value in main.

    --
    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.
  • Kevin Malachowski at Aug 13, 2014 at 8:30 pm
    Also, the break in the select case of <-stopChan does not do what you want it to do, try return or a label to specify what to break out of (it breaks out of the select{}, not the for).

    --
    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.
  • Shane Turner at Aug 13, 2014 at 10:48 pm
    Thanks for the help/suggestions (I didn't even know select had a break).
    So I understand that by making the Start method a pointer receiver it
    works, but what if Start is part of an interface method you're implementing?
    How do you get around not having a pointer receiver to directly manipulate
    the concrete type and its members?

    Thanks again!

    On Wednesday, August 13, 2014 3:30:17 PM UTC-5, Kevin Malachowski wrote:

    Also, the break in the select case of <-stopChan does not do what you want
    it to do, try return or a label to specify what to break out of (it breaks
    out of the select{}, not the for).
    --
    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.
  • Shane Turner at Oct 29, 2014 at 6:39 pm
    Bump . . anybody have some suggestions here?
    On Wednesday, August 13, 2014 5:47:57 PM UTC-5, Shane Turner wrote:

    Thanks for the help/suggestions (I didn't even know select had a break).
    So I understand that by making the Start method a pointer receiver it
    works, but what if Start is part of an interface method you're implementing?
    How do you get around not having a pointer receiver to directly manipulate
    the concrete type and its members?

    Thanks again!

    On Wednesday, August 13, 2014 3:30:17 PM UTC-5, Kevin Malachowski wrote:

    Also, the break in the select case of <-stopChan does not do what you
    want it to do, try return or a label to specify what to break out of (it
    breaks out of the select{}, not the for).
    --
    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.
  • James Bardin at Oct 29, 2014 at 7:01 pm

    On Wednesday, October 29, 2014 2:39:18 PM UTC-4, Shane Turner wrote:
    Bump . . anybody have some suggestions here?
    Suggestions about what exactly?

    On Wednesday, August 13, 2014 5:47:57 PM UTC-5, Shane Turner wrote:

    Thanks for the help/suggestions (I didn't even know select had a break).
    So I understand that by making the Start method a pointer receiver it
    works, but what if Start is part of an interface method you're implementing?
    How do you get around not having a pointer receiver to directly
    manipulate the concrete type and its members?
    I don't follow. If you make it a pointer receiver, it works.

    --
    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.
  • Shane Turner at Oct 29, 2014 at 7:10 pm
    Yes, making a pointer receiver works, but like I said earlier, if the
    method is satisfying an interface, it can't be a pointer receiver, it has
    to be a value which means that any modifications of the struct's members
    only modifies copies of those members. Maybe a simpler example will
    illustrate. http://play.golang.org/p/ap8WRQcYY6, -- notice the size of the
    value stays the same.
    On Wednesday, October 29, 2014 2:00:40 PM UTC-5, James Bardin wrote:

    On Wednesday, October 29, 2014 2:39:18 PM UTC-4, Shane Turner wrote:

    Bump . . anybody have some suggestions here?
    Suggestions about what exactly?

    On Wednesday, August 13, 2014 5:47:57 PM UTC-5, Shane Turner wrote:

    Thanks for the help/suggestions (I didn't even know select had a break).
    So I understand that by making the Start method a pointer receiver it
    works, but what if Start is part of an interface method you're implementing?
    How do you get around not having a pointer receiver to directly
    manipulate the concrete type and its members?
    I don't follow. If you make it a pointer receiver, it works.
    --
    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.
  • James Bardin at Oct 29, 2014 at 7:12 pm

    On Wed, Oct 29, 2014 at 3:10 PM, Shane Turner wrote:

    Yes, making a pointer receiver works, but like I said earlier, if the
    method is satisfying an interface, it can't be a pointer receiver
    Why not?

    http://play.golang.org/p/ObZlL5PJI2

    --
    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.
  • Shane Turner at Oct 29, 2014 at 7:22 pm
    Ok, that is a subtle concept of pointer receivers and interfaces I have
    missed.
    That little tweak of creating a Logger from a "pointer" to an
    implementation instead of using it directly.
    Thanks man! I was banging my head on that one. Loving the language but
    still learning the "ins and outs".

    Thanks again!
    Shane

    On Wednesday, October 29, 2014 2:12:47 PM UTC-5, James Bardin wrote:



    On Wed, Oct 29, 2014 at 3:10 PM, Shane Turner <kola...@gmail.com
    <javascript:>> wrote:
    Yes, making a pointer receiver works, but like I said earlier, if the
    method is satisfying an interface, it can't be a pointer receiver
    Why not?

    http://play.golang.org/p/ObZlL5PJI2
    --
    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
postedAug 13, '14 at 8:06p
activeOct 29, '14 at 7:22p
posts9
users3
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase