https://github.com/ninedraft/limiter
A simple concurrency limiter
https://github.com/ninedraft/limiter
async-programming asynchronous-programming go golang golang-package limiter limiting synchronization
Last synced: 3 days ago
JSON representation
A simple concurrency limiter
- Host: GitHub
- URL: https://github.com/ninedraft/limiter
- Owner: ninedraft
- License: mit
- Created: 2017-09-26T19:03:58.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-01-21T12:01:08.000Z (about 8 years ago)
- Last Synced: 2024-06-20T16:37:30.007Z (over 1 year ago)
- Topics: async-programming, asynchronous-programming, go, golang, golang-package, limiter, limiting, synchronization
- Language: Go
- Homepage:
- Size: 2.93 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# limiter
A dead simple goroutine limiter.
Example:
```go
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