Giter Site home page Giter Site logo

jigneshsatam / parallel Goto Github PK

View Code? Open in Web Editor NEW
7.0 3.0 1.0 22 KB

parallel executes any tasks in parallel by using Golang fanout fanin concurrency pattern

License: MIT License

Go 100.00%
go golang concurrency parallel fanout fanin parallelly golang-library golang-package

parallel's Introduction

parallel

Concurrency Made Easy


Go Report Card Build   Test Coverage Issue Count Code Climate GoDoc License: MIT

parallel executes independent tasks in parallel by using Golang fanout fanin concurrency pattern

Installation

go get -u github.com/JigneshSatam/parallel

Usage

Example code snippet: https://play.golang.org/p/uHBw49pwFwt

Step 1: Import the package

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
// 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.
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 file for details

parallel's People

Contributors

jigneshsatam avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

wnz27

parallel's Issues

【Discuss and Proposal】Some variable name may be better understand if minor changes

1

parallel_change1
first, I think the fanout func is send executor to out for async run, the executor run logic real in outer ,
so I think the func addIn name may not be suitable, so may be addOut more better understand.
unless u use executor.addIn something like this to call this func, but i think this func return <-chan interface{},
if use executor.addIn may should not to return something. so this func i think use add or addExecutor or addOut, may be addOut better, because the func's param is executor, when call is very easy readble.

2

parallel_change2
second, this func out actually it is receive result from out , so addToOut actuall it is receive value from out chan ,
so I think inner fanin func addToOut may be receiveFrom better to understand.

Proposal

  • I want to add some benchmark for project.
  • by the way if u dont mind i change this func name for project.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.