Skip to content

A way to limit the parallelism while running multiple tasks

License

Notifications You must be signed in to change notification settings

zmalik/go-routine-pool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

go-routine-pool

A way to limit the parallelism while running multiple tasks.

Under the hood it uses Go routines.

Usage

package main

import (
    pool "github.com/zmalik/go-routine-pool"
)

func parallelTask(x int, y *int) int {
	fmt.Printf("%d\n", x)
	*y = x + *y
	return x
}


func main() {
    routinePool := pool.NewDefaultRoutinePool()

    var result int
    for i := 0; i < 20; i++ {
        routinePool.Run(parallelTask, i, &result)
    }
    fmt.Println(result)
}

Limiting number of Go routines

routinePool := pool.NewRoutinePool(5)

Why?

Power is nothing without control

Using Go routines one can easily rage the power of routines without limiting how many parallel tasks are running.

This library helps to control that in easy way

About

A way to limit the parallelism while running multiple tasks

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages