gorc

package module
v0.0.0-...-bf35b3d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 28, 2015 License: MIT Imports: 2 Imported by: 2

README

gorc

set thresholds on number of running goroutines

Can increase and decrease a counter when starting or stopping a goroutine. It can wait for a minimum or maximum number of goroutines running, thus allowing to set thresholds for the number of gorc governed goroutines running at the same time.

minimalist docs at https://godoc.org/github.com/mr51m0n/gorc

import "github.com/mr51m0n/gorc"

an example:

var gorc0 gorc.Gorc

func main() {
	for i := 0; i < 20; i++ {
		gorc0.Inc()
		go withgorc(i)
		gorc0.WaitLow(5) // no more then five goroutines governed by gorc0 are allowed at the same time
	}
}

func init() {
	gorc0.Init()
}

func withgorc(i int) {
	defer gorc0.Dec() // decrease counter when finished
	fmt.Println("Nr.", i, " ", gorc0.Get(), "gorc goroutines running..")
	time.Sleep(time.Duration(rand.Int31n(2000)) * time.Millisecond)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Gorc

type Gorc struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*Gorc) Dec

func (g *Gorc) Dec()

Dec decreases the counter by one.

func (*Gorc) DecBy

func (g *Gorc) DecBy(b int)

DecBy decreases the counter by b.

func (*Gorc) Get

func (g *Gorc) Get() int

GetCount returns an integer holding the count.

func (*Gorc) Inc

func (g *Gorc) Inc()

Inc increases the counter by one.

func (*Gorc) IncBy

func (g *Gorc) IncBy(b int)

IncBy increases the counter by b.

func (*Gorc) Init

func (g *Gorc) Init()

Init initializes a new Gorc instance

func (*Gorc) SetWaitMillis

func (g *Gorc) SetWaitMillis(w int)

SetWaitMillis sets the time in milliseconds the Wait function waits between checking the count against the given integer.

func (*Gorc) WaitHigh

func (g *Gorc) WaitHigh(w int)

WaitHigh will return as soon as the Gorc counter goes above w. e.g. wait until at least w goroutines are started.

func (*Gorc) WaitLow

func (g *Gorc) WaitLow(w int)

WaitLow will return as soon as the Gorc counter falls below w. e.g. wait until all but w goroutines are stopped.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL