https://github.com/jigneshsatam/parallel
parallel executes any tasks in parallel by using Golang fanout fanin concurrency pattern
https://github.com/jigneshsatam/parallel
concurrency fanin fanout go golang golang-library golang-package parallel parallelly
Last synced: about 2 months ago
JSON representation
parallel executes any tasks in parallel by using Golang fanout fanin concurrency pattern
- Host: GitHub
- URL: https://github.com/jigneshsatam/parallel
- Owner: jigneshsatam
- License: mit
- Created: 2020-06-24T15:30:12.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2023-02-15T08:24:29.000Z (over 2 years ago)
- Last Synced: 2025-03-30T13:03:24.495Z (about 2 months ago)
- Topics: concurrency, fanin, fanout, go, golang, golang-library, golang-package, parallel, parallelly
- Language: Go
- Homepage:
- Size: 21.5 KB
- Stars: 7
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# parallel
### **Concurrency Made Easy**
***
### [](https://goreportcard.com/report/github.com/JigneshSatam/parallel) [](https://github.com/JigneshSatam/parallel/actions/workflows/go.yml) [](https://codeclimate.com/github/JigneshSatam/parallel/test_coverage) [](https://codeclimate.com/github/JigneshSatam/parallel) [](https://codeclimate.com/github/JigneshSatam/parallel) [](https://godoc.org/github.com/JigneshSatam/parallel) [](https://github.com/JigneshSatam/parallel/blob/master/LICENSE)### **parallel executes independent tasks in parallel by using Golang fanout fanin concurrency pattern**
## Installation
```go
go get -u github.com/JigneshSatam/parallel
```## Usage
Example code snippet: https://play.golang.org/p/uHBw49pwFwt
### Step 1: Import the package
```go
import (
"github.com/JigneshSatam/parallel"
)
```### Step 2: Create `Execute() interface{}` method for `user defined type`
- Let `employee` be a user-defined type
- Suppose fetching `employee details` is an independent task and needs to be done be in parallel
- Create a method `Execute()` for `employee` type
- Signature of Execute method `Execute() interface{}`
- Add the code to fetch the `employee details` in this `Execute()` method
```go
// employee -> Let `employee` be a user-defined type
type employee struct {
name string
}// Execute() -> Create `Execute() interface{}` method for employee type
func (e employee) Execute() interface{} {
return employeeDetails(e)
}func employeeDetails(e employee) string {
return "Employee details Name: " + e.name
}
```### Step 3: Call `parallel.Run()` method
- Call `parallel.Run` by passing list of employees who's details to be fetched.
```go
func Example() {
employees := []employee{employee{"foo"}, employee{"bar"}, employee{"baz"}}// Call `parallel.Run()` to start parallel execution
outputChannel := parallel.Run(employees)for op := range outputChannel {
// Cast `interface{}` to desired output type
output := op.(string)
fmt.Println(output)
}
}// Unordered output:
// "Employee details Name: bar"
// "Employee details Name: foo"
// "Employee details Name: baz"
```## Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.Please make sure to update the tests as appropriate.
## License
This project is licensed under the **MIT** License - see the [LICENSE.md](https://github.com/JigneshSatam/parallel/blob/master/LICENSE) file for details