routine

package
v0.0.0-...-732c4ef Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2022 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package routine is defined a routine group to manage many routines

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Group

type Group interface {
	// Add is append routine func to  group
	Add(fn func())
	// Run is run group and wait all finish
	Run()
}

Group is manage some routine in a group

func NewGroup

func NewGroup() Group

NewGroup create routine group

Example
rgp := NewGroup()
var b bool
var c []int
var sum int32
// add some routine to group
rgp.Add(func() {
	b = true
	atomic.AddInt32(&sum, 1)
})
rgp.Add(func() {
	c = append(c, 1)
	atomic.AddInt32(&sum, 1)
})
// run all routines and block until all routine exit
rgp.Run()
fmt.Println(b, c, sum)
// true [1] 2
Output:

Jump to

Keyboard shortcuts

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