conc – github.com/sourcegraph/conc Index | Examples | Files | Directories

package conc

import "github.com/sourcegraph/conc"

Index

Examples

Types

type WaitGroup

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

WaitGroup is the primary building block for scoped concurrency. Goroutines can be spawned in the WaitGroup with the Go method, and calling Wait() will ensure that each of those goroutines exits before continuing. Any panics in a child goroutine will be caught and propagated to the caller of Wait().

The zero value of WaitGroup is usable, just like sync.WaitGroup. Also like sync.WaitGroup, it must not be copied after first use.

Example

Code:

{
	var count atomic.Int64

	var wg WaitGroup
	for i := 0; i < 10; i++ {
		wg.Go(func() {
			count.Add(1)
		})
	}
	wg.Wait()

	fmt.Println(count.Load())
	// Output:
	// 10
}

Output:

10

func NewWaitGroup

func NewWaitGroup() *WaitGroup

NewWaitGroup creates a new WaitGroup.

func (*WaitGroup) Go

func (h *WaitGroup) Go(f func())

Go spawns a new goroutine in the WaitGroup.

func (*WaitGroup) Wait

func (h *WaitGroup) Wait()

Wait will block until all goroutines spawned with Go exit and will propagate any panics spawned in a child goroutine.

func (*WaitGroup) WaitAndRecover

func (h *WaitGroup) WaitAndRecover() *panics.RecoveredPanic

WaitAndRecover will block until all goroutines spawned with Go exit and will return a *panics.RecoveredPanic if one of the child goroutines panics.

Source Files

waitgroup.go

Directories

PathSynopsis
iter
panics
pool
streamPackage stream provides a concurrent, ordered stream implementation.
Version
v0.2.0
Published
Jan 17, 2023
Platform
windows/amd64
Imports
2 packages
Last checked
now

Tools for package owners.