wait

package
Version: v0.0.0-...-dc4534b Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2015 License: MIT Imports: 1 Imported by: 0

README

github.com/markbates/going/wait

Wait cleans up the pattern around using sync.WaitGroup.

Installation

$ go get https://github.com/markbates/wait

Usage

Before:

users := []User{User{"A"}, User{"B"}}
var w sync.WaitGroup
length := len(users)
w.Add(length)
for i := 0; i < length; i++ {
  go func(w *sync.WaitGroup, index int) {
    user := users[index]
    user.Name = fmt.Sprintf("User: %d", index)
    users[i] = user
    w.Done()
  }(&w, i)
}
w.Wait()

After:

users := []User{User{"A"}, User{"B"}}
Wait(len(users), func(index int) {
  user := users[index]
  user.Name = fmt.Sprintf("User: %d", index)
  users[index] = user
})

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Wait

func Wait(length int, block func(index int))

Wait cleans up the pattern around using sync.WaitGroup

Types

This section is empty.

Source Files

Jump to

Keyboard shortcuts

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