waitgroup

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2022 License: MIT Imports: 1 Imported by: 0

README

WaitGroup - Parallel-Controlled WaitGroup

PkgGoDev Build Status Go Report Card Coverage Status GitHub issues Release

Installation

To install the package, run:

go get github.com/go-zoox/waitgroup

Getting Started

import (
  "testing"
  "github.com/go-zoox/waitgroup"
)

func main(t *testing.T) {
  wg := waitgroup.New(3)
  jobs := []func(){}

  for i := 0; i < 10; i++ {
    index := i
    jobs = append(jobs, func() {
      time.Sleep(time.Second)
      fmt.Println(index)
    })
  }

  wg.Add(jobs...)
  
  wg.Wait()
}

License

GoZoox is released under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Version = "1.0.0"

Version is the current version of the package.

Functions

This section is empty.

Types

type WaitGroup

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

WaitGroup implements a simple goroutine pool.

func New

func New(size int) *WaitGroup

New creates a waitgroup with a specific size (the maxium number of goroutines to run at the same time). If you use -1 as the size, all items will run concurrentlu (just like a normal sync.WaitGroup).

func (*WaitGroup) Add

func (wg *WaitGroup) Add(fns ...func())

Add adds the function to the waitgroup.

func (*WaitGroup) Done

func (wg *WaitGroup) Done()

Done pops one out of the pool.

func (*WaitGroup) PendingCount

func (wg *WaitGroup) PendingCount() int64

PendingCount returns the number of pending tasks.

func (*WaitGroup) Wait

func (wg *WaitGroup) Wait()

Wait waits the pool empty.

Jump to

Keyboard shortcuts

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