Thursday, March 2, 2017

waitforme waitgroup shouting

package main

import (
"fmt"
"sync"
)

func main() {
waitforme := &sync.WaitGroup{}
for i := 0; i < 200; i++ {
// add for each operation
waitforme.Add(1)
go shout(waitforme)
}

// wait for all to complete otherwise Go quits automatically!!!
waitforme.Wait()
}

func shout(waitgroup *sync.WaitGroup) {
fmt.Println("whoo hooo")

// done for each completed operation
waitgroup.Done()
}

No comments:

Post a Comment