hiranya / goroutinepool

A simple goroutine pool for Golang

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

goroutinepool

A simple goroutine pool for Golang.

goroutinepool uses channels as a semaphore to implement this.

Documentation

https://godoc.org/github.com/hiranya/goroutinepool

Example

See example/example1.go for a working example

package main

import (
	"fmt"
	"github.com/hiranya/goroutinepool"
)

func main() {
	cmd := &CounterCmd{}

	pool := goroutinepool.Pool{}

	// param1: number of iterations
	// param2: level of concurrency required
	// param3: the command/job to execute
	pool.Run(30, 10, cmd)
}

type CounterCmd struct {
}

// Provide an Exec() function to implement the Command interface provided by goroutinepool library
func (cmd *CounterCmd) Exec() {
	// -----
	// your time consuming job
	// -----
}

About

A simple goroutine pool for Golang

License:GNU General Public License v3.0


Languages

Language:Go 100.0%