concurrency

package
v0.0.0-...-39cffea Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2018 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Barrier

type Barrier struct {
	// contains filtered or unexported fields
}

Barrier for limited go-routines

Example
b := NewBarrier(15)
log.SetFlags(log.LstdFlags | log.Lmicroseconds)

wg := &sync.WaitGroup{}
for i := 0; i < 100; i++ {

	b.Advance()
	wg.Add(1)
	go func(i int) {
		defer wg.Done()
		defer b.Done()

		time.Sleep(time.Millisecond * 500)
		log.Printf("done %d", i)
	}(i)
}
wg.Done()
Output:

func NewBarrier

func NewBarrier(num int) *Barrier

NewBarrier creates new object and inits it

func (*Barrier) Advance

func (b *Barrier) Advance()

Advance 1 step if there still is a unused go-routine

func (*Barrier) Done

func (b *Barrier) Done()

Done means outside will release the go routine

Jump to

Keyboard shortcuts

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