Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rafaeljesus/parallel-fn
Run functions in parallel :comet:
https://github.com/rafaeljesus/parallel-fn
concurrency go goroutines
Last synced: about 1 month ago
JSON representation
Run functions in parallel :comet:
- Host: GitHub
- URL: https://github.com/rafaeljesus/parallel-fn
- Owner: rafaeljesus
- License: mit
- Created: 2017-06-18T09:47:54.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-01-01T20:34:49.000Z (almost 7 years ago)
- Last Synced: 2024-07-31T20:51:54.268Z (5 months ago)
- Topics: concurrency, go, goroutines
- Language: Go
- Homepage:
- Size: 10.7 KB
- Stars: 36
- Watchers: 4
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-go - parallel-fn - Run functions in parallel. (Goroutines / Search and Analytic Databases)
- awesome-go - parallel-fn - Run functions in parallel - ★ 20 (Goroutines)
- awesome-go-extra - parallel-fn - 06-18T09:47:54Z|2018-01-01T20:34:49Z| (Goroutines / Advanced Console UIs)
README
## Parallel fn
* Run functions in parallel.
* Limit the number of goroutines running at the same time.## Installation
```bash
go get -u github.com/rafaeljesus/parallel-fn
```## Usage
### Run
```go
package mainimport (
"errors""github.com/rafaeljesus/parallel-fn"
)func main() {
timeout := time.After(2 * time.Second)
fn1 := func() error { return nil }
fn2 := func() error { return errors.New("BOOM!") }for {
select {
case err := <-Run(fn1, fn2):
// catch errors
case <-timeout:
// handle timeout
}
}
}
```### RunLimit
```go
package mainimport (
"errors""github.com/rafaeljesus/parallel-fn"
)func main() {
timeout := time.After(2 * time.Second)
fn1 := func() error { return nil }
fn2 := func() error { return errors.New("BOOM!") }
fn3 := func() error { nil }
fn4 := func() error { nil }for {
select {
case err := <-RunLimit(2, fn1, fn2, fn3, fn4):
// catch errors
case <-timeout:
// handle timeout
}
}
}
```## Contributing
- Fork it
- Create your feature branch (`git checkout -b my-new-feature`)
- Commit your changes (`git commit -am 'Add some feature'`)
- Push to the branch (`git push origin my-new-feature`)
- Create new Pull Request## Badges
[![Build Status](https://circleci.com/gh/rafaeljesus/parallel-fn.svg?style=svg)](https://circleci.com/gh/rafaeljesus/parallel-fn)
[![Go Report Card](https://goreportcard.com/badge/github.com/rafaeljesus/parallel-fn)](https://goreportcard.com/report/github.com/rafaeljesus/parallel-fn)
[![Go Doc](https://godoc.org/github.com/rafaeljesus/parallel-fn?status.svg)](https://godoc.org/github.com/rafaeljesus/parallel-fn)---
> GitHub [@rafaeljesus](https://github.com/rafaeljesus) ·
> Medium [@_jesus_rafael](https://medium.com/@_jesus_rafael) ·
> Twitter [@_jesus_rafael](https://twitter.com/_jesus_rafael)