https://github.com/umpc/concurrency-limit
Easily limit the number of running goroutines per given group of functions.
https://github.com/umpc/concurrency-limit
Last synced: 3 months ago
JSON representation
Easily limit the number of running goroutines per given group of functions.
- Host: GitHub
- URL: https://github.com/umpc/concurrency-limit
- Owner: umpc
- License: mit
- Created: 2017-10-22T05:05:32.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-10-22T07:49:21.000Z (over 8 years ago)
- Last Synced: 2024-06-20T17:30:50.071Z (almost 2 years ago)
- Language: Go
- Homepage:
- Size: 3.91 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ConcurrencyLimit
[](https://godoc.org/github.com/umpc/concurrency-limit)
Easily limit the number of running goroutines per given group of functions.
```sh
go get -u github.com/umpc/concurrency-limit
```
## Example
```go
const limit = 2
limitedConcurrency := climit.New(limit)
go limitedConcurrency.Exec(func() {
fmt.Println("Hello world!")
})
```
See the test file for a more in-depth example.
## Benchmarks
```sh
BenchmarkNew2-8 30000000 43.4 ns/op 96 B/op 1 allocs/op
BenchmarkExec2-8 5000000 339 ns/op 0 B/op 0 allocs/op
```
The above benchmark tests were ran using a 2.6GHz Intel Core i7-6700HQ (Skylake) CPU.
## License
The source code is available under the [MIT License](https://opensource.org/licenses/MIT).