NoUseFreak / go-parallel

Package go-parallel aims to simplify processing data in parallel by providing a small helper.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

go-parallel

Build Status GoDoc 

Package go-parallel aims to simplify processing data in parallel by providing a small helper.

package main

import (
    "fmt"
    "time"

    "github.com/NoUseFreak/go-parallel"
)

type Payload struct {
    Number int
}

func main() {
    input := parallel.Input{}
    for i := 0; i < 20; i++ {
        input = append(input, Payload{Number: i})
    }

    p := parallel.Processor{Threads: 5}
    result := p.Process(input, func(i interface{}) interface{} {
        item := i.(Payload)
        time.Sleep(1 * time.Second)
        item.Number = item.Number * 2

        return item
    })

    fmt.Printf("%v\n", result)
}

About

Package go-parallel aims to simplify processing data in parallel by providing a small helper.

License:MIT License


Languages

Language:Go 100.0%