Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

ninedraft/limiter

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

limiter

A dead simple goroutine limiter. Example:

names := []string{"John", "Ada", "Merlin", "Tanya"}
// parameter is a limit
// .Start() method blocks until number 
// of running goroutines is reduced.
limit := limiter.New(2)
for _, name := range names {
    go func(name string, done func()) {
        defer done()
        fmt.Printf("Hello, %s!\n", name)
    // .Start()) blocks f the number of workers 
    // approaches the specified limit, 
    // then waits until the number of active workers decreases.
    }(name, limit.Start())
}
// .Wait() blocks until all tasks are completed.
limit.Wait()

To use limiter import it in your project or just copy-paste source code

Morty Proxy This is a proxified and sanitized view of the page, visit original site.