FAQ
Dear Gophers,

I often face the problem of having to limit concurrency in my programs
which I solve using a combination of a buffered channel to actually limit
the number of concurrent goroutines and a sync.Wait to wait for all the
goroutines to complete. I've come up with this structure that embeds both
functionalities:

type ConcLimiter struct {
*sync.WaitGroup
Pool chan struct{}
}

Here is an example of how it's used:
https://play.golang.org/p/XuglM2JSrO

I would like to have some feedback about this proposal and if there are
more idiomatic ways of achieving the same.

Thanks for your help,
Pablo

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

  • Sokolov Yura at Jun 1, 2016 at 11:45 pm
    I like it.

    --
    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.
  • Thomas de Zeeuw at Jun 4, 2016 at 10:14 am
    I wouldn't make the sync.WaitGroup public, because then you can call Add()
    and Done() on it without considering the limit. Otherwise it looks nice.

    Op woensdag 1 juni 2016 04:34:16 UTC+2 schreef Pablo Rozas-Larraondo:
    Dear Gophers,

    I often face the problem of having to limit concurrency in my programs
    which I solve using a combination of a buffered channel to actually limit
    the number of concurrent goroutines and a sync.Wait to wait for all the
    goroutines to complete. I've come up with this structure that embeds both
    functionalities:

    type ConcLimiter struct {
    *sync.WaitGroup
    Pool chan struct{}
    }

    Here is an example of how it's used:
    https://play.golang.org/p/XuglM2JSrO

    I would like to have some feedback about this proposal and if there are
    more idiomatic ways of achieving the same.

    Thanks for your help,
    Pablo
    --
    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 1, '16 at 2:34a
activeJun 4, '16 at 10:14a
posts3
users3
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase