wait

package module
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2019 License: MIT Imports: 2 Imported by: 5

README

Build Status

What

Sugared sync.WaitGroup

Why

LGTM

Example

package main

import (
    "context"
    "fmt"

    "github.com/chapsuk/wait"
)

func do()                               { fmt.Print("do\n") }
func doWithArgs(i, j int)               { fmt.Printf("doWith args: %d %d\n", i, j) }
func doWithContext(ctx context.Context) { fmt.Printf("doWithContext\n") }

func main() {
    wg := wait.Group{}

    wg.Add(do)
    wg.Add(func() {
        doWithArgs(1, 2)
    })
    wg.AddMany(10, do)
    wg.AddWithContext(context.TODO(), doWithContext)
    wg.AddManyWithContext(context.TODO(), 10, doWithContext)
    wg.Wait()
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Group

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

Group is wrapper over sync.WaitGroup

func (*Group) Add

func (g *Group) Add(f func())

Add function calling argument function in a separate goroutine with sync.WaitGroup control

func (*Group) AddMany

func (g *Group) AddMany(count int, f func())

AddMany running call group.Add count times

func (*Group) AddManyWithContext

func (g *Group) AddManyWithContext(ctx context.Context, count int, f func(context.Context))

AddManyWithContext running call group.AddWithContext count times

func (*Group) AddWithContext

func (g *Group) AddWithContext(ctx context.Context, f func(context.Context))

AddWithContext function calling argument function with context in a separate goroutine with sync.WaitGroup control

func (*Group) Wait

func (g *Group) Wait()

Wait blocks until all added functions will be completed

Jump to

Keyboard shortcuts

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