Documentation ¶
Overview ¶
Package parallel executes independent tasks in parallel by using Golang fanout fanin concurrency pattern.
Concurrency Made Easy
Example ¶
package main import ( "fmt" "github.com/JigneshSatam/parallel" ) // customType -> Let `customType` be a user-defined type type customType int // Execute -> Create `Execute() interface{}` method for customType func (c customType) Execute() interface{} { return c * c } func main() { tasks := []customType{1, 2, 3, 4, 5} // Call `parallel.Run()` to start parallel execution outputChannel := parallel.Run(tasks) for op := range outputChannel { // Cast interface{} to desired output type output := op.(customType) fmt.Println(output) } }
Output: 1 4 9 16 25
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Run ¶ added in v0.2.0
func Run(tasks ...interface{}) <-chan interface{}
Run starts the parallel execution of the tasks provided.
It casts user-defined type tasks into `Executor interface` to builds executors.
To cast the task in an `Executor interface` the user-defined type `task` needs to have method with `Execute() interface{}` signature.
Types ¶
Click to show internal directories.
Click to hide internal directories.