• Stars
    star
    411
  • Rank 105,247 (Top 3 %)
  • Language
    Go
  • License
    MIT License
  • Created about 8 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

SizedWaitGroup has the same role and close to the same API as the Golang sync.WaitGroup but it adds a limit on the amount of goroutines started concurrently.

SizedWaitGroup

GoDoc

SizedWaitGroup has the same role and API as sync.WaitGroup but it adds a limit of the amount of goroutines started concurrently.

SizedWaitGroup adds the feature of limiting the maximum number of concurrently started routines. It could for example be used to start multiples routines querying a database but without sending too much queries in order to not overload the given database.

Example

package main

import (
        "fmt"
        "math/rand"
        "time"

        "github.com/remeh/sizedwaitgroup"
)

func main() {
        rand.Seed(time.Now().UnixNano())

        // Typical use-case:
        // 50 queries must be executed as quick as possible
        // but without overloading the database, so only
        // 8 routines should be started concurrently.
        swg := sizedwaitgroup.New(8)
        for i := 0; i < 50; i++ {
                swg.Add()
                go func(i int) {
                        defer swg.Done()
                        query(i)
                }(i)
        }

        swg.Wait()
}

func query(i int) {
        fmt.Println(i)
        ms := i + 500 + rand.Intn(500)
        time.Sleep(time.Duration(ms) * time.Millisecond)
}

License

MIT

Copyright

RΓ©my Mathieu Β© 2016

More Repositories

1

diago

Diago is a visualization tool for CPU profiles and heap snapshots generated with `pprof`.
Go
358
star
2

mehstation

Opensource front-end for emulation / retro / TV box.
C
54
star
3

gost

OLD AND DEPRECATED - A realtime distributed computation system using NSQ and Etcd.
Go
18
star
4

upd

Upload from the command-line, share with your browsers.
Go
18
star
5

fatbin

Compress an executable and its resources in an auto-extractible and runnable file.
Go
17
star
6

mboximporter

MBox file importer to MongoDB
Go
8
star
7

mehcam

Motion detection for D-Link DCS-932L
Go
8
star
8

mehteor

OpenGL Game engine
C
7
star
9

mehstation-config

Configuration tool for https://github.com/remeh/mehstation.
C++
5
star
10

memoiz

Never forget a memo again.
Go
5
star
11

meh-old

meh is remeh's personal code editor
C++
5
star
12

reddit-audiences

Track audience of subreddits.
Go
4
star
13

go-webserver

Minimal, simple and powerful HTTP framework in Go. -- Old experimentation. You should use golang.org/pkg/net/http instead.
Go
4
star
14

statsd-zig

Basic statsd implementation in Ziglang.
Zig
4
star
15

qubuto

Quick bug-tracking tool.
JavaScript
3
star
16

mehtadata

Games metadata scraper using thegamesdb.net
Go
3
star
17

pgen

Create images with generated particles.
Go
2
star
18

smartwitter

Industrialize your Twitter usage.
Go
2
star
19

wcie

What Can I Eat - Twitter search queries analyzer in Golang
Go
2
star
20

home-sensors-server

Server receiving data from the Arduino+Olimex 4G Kit about home sensors
Go
2
star
21

goid

Basic package to generate pseudo-random unique IDs.
Go
1
star
22

galactictaxi

Galactit Taxi - Ludum Dare 23 Entry
C++
1
star
23

go-subtitles

Retrieve movies / series subtitles from a filename.
Go
1
star
24

soulkeeper

GameDevParty Jam #4 Participation - Soul Keeper team.
Lua
1
star
25

meh2d

Meh2D is a simple game library based upon Allegro 5 to easily realize 2d games in C++
C++
1
star
26

go-rrd

A golang client for talking to rrdcached
Go
1
star
27

logr

logr is a small log rotating struct compatible with io.Writer, suitable for the default log package
Go
1
star
28

memoiz-front

React Front for Memoiz. Go backend β†’ https://github.com/remeh/memoiz
JavaScript
1
star
29

meh

remeh's personal code editor
Zig
1
star