https://github.com/rafaeljesus/parallel-fn
Run functions in parallel :comet:
https://github.com/rafaeljesus/parallel-fn
concurrency go goroutines
Last synced: 7 months 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 8 years ago)
- Default Branch: master
- Last Pushed: 2018-01-01T20:34:49.000Z (almost 8 years ago)
- Last Synced: 2024-07-31T20:51:54.268Z (over 1 year 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-cn - parallel-fn - fn) [![godoc][D]](https://godoc.org/github.com/rafaeljesus/parallel-fn) (Goroutines / 检索及分析资料库)
- awesome-go - parallel-fn - Run functions in parallel. (Goroutines / Search and Analytic Databases)
- awesome-go - parallel-fn - | - | - | (Goroutines / Advanced Console UIs)
- awesome-go-plus - parallel-fn - Run functions in parallel.  (Goroutines / Search and Analytic Databases)
- awesome-go - parallel-fn - Run functions in parallel. (Goroutines / Search and Analytic Databases)
- awesome-go - parallel-fn - Run functions in parallel. - :arrow_down:0 - :star:15 (Goroutines / Advanced Console UIs)
- awesome-go - parallel-fn - Run functions in parallel - ★ 20 (Goroutines)
- awesome-go - parallel-fn - Run functions in parallel. (Goroutines / Search and Analytic Databases)
- fucking-awesome-go - parallel-fn - Run functions in parallel. (Goroutines / Search and Analytic Databases)
- awesome-go - parallel-fn - Run functions in parallel. (Goroutines / Advanced Console UIs)
- awesome-go - parallel-fn - Run functions in parallel. (Goroutines / Advanced Console UIs)
- awesome-go-cn - parallel-fn
- awesome-go-extra - parallel-fn - 06-18T09:47:54Z|2018-01-01T20:34:49Z| (Goroutines / Advanced Console UIs)
- awesome-go-cn - parallel-fn
- awesome-go-with-stars - parallel-fn - Run functions in parallel. (Goroutines / Search and Analytic Databases)
- awesome-go - parallel-fn - Run functions in parallel. (Goroutines / Search and Analytic Databases)
- awesome-go - parallel-fn - Run functions in parallel. (Goroutines / Search and Analytic Databases)
- awesome-Char - parallel-fn - Run functions in parallel. (Goroutines / Advanced Console UIs)
- awesome-go-cn - parallel-fn - fn) [![godoc][D]](https://godoc.org/github.com/rafaeljesus/parallel-fn) (Goroutines / 检索及分析资料库)
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 main
import (
"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 main
import (
"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
[](https://circleci.com/gh/rafaeljesus/parallel-fn)
[](https://goreportcard.com/report/github.com/rafaeljesus/parallel-fn)
[](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)