FAQ
I trying to write statistics module. I need to to get len(...) from
different channels (only len(), no other operations with channel). How can
i pass chan *MyObj and chan int64 as parameter to the same function?
func CreateChannelWatcher(target chan interface{}) {
.. get len(target) each second
}

func main() {
c1 := make(chan *MyObj,10000)
c2 := make(chan int64,10000)
CreateChannelWatcher(c1)
CreateChannelWatcher(c2)
}

Of cause i got error abou wrong type (((

--
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/groups/opt_out.

Search Discussions

  • Christoph Hack at Mar 1, 2014 at 3:18 pm
    You need reflection if you want a general solution. Pass an "interface{}"
    instead of an "chan interface{}" and take a look at the "reflect" package,
    especially the function "ValueOf" and the "Len" method.

    -christoph
    On Saturday, March 1, 2014 3:48:08 PM UTC+1, Павел Иванцов wrote:

    I trying to write statistics module. I need to to get len(...) from
    different channels (only len(), no other operations with channel). How can
    i pass chan *MyObj and chan int64 as parameter to the same function?
    func CreateChannelWatcher(target chan interface{}) {
    .. get len(target) each second
    }

    func main() {
    c1 := make(chan *MyObj,10000)
    c2 := make(chan int64,10000)
    CreateChannelWatcher(c1)
    CreateChannelWatcher(c2)
    }

    Of cause i got error abou wrong type (((
    --
    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/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedMar 1, '14 at 2:48p
activeMar 1, '14 at 3:18p
posts2
users2
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase