Skip to content

Instantly share code, notes, and snippets.

@SteveBate
Created August 24, 2014 17:54
Show Gist options
  • Save SteveBate/4e23f69d5939ad167135 to your computer and use it in GitHub Desktop.
Save SteveBate/4e23f69d5939ad167135 to your computer and use it in GitHub Desktop.
Example showing use of Waitgroups and with the time.After channel. Remove the "go" call to have all calls to UpdateSchedulesReport run sequentially otherwise they run concurrently
package main
import (
"fmt"
"sync"
"time"
)
func main() {
var w sync.WaitGroup
w.Add(3)
go UpdateSchedulesReport(&w)
go UpdateSchedulesReport(&w)
go UpdateSchedulesReport(&w)
w.Wait()
fmt.Println("all over!")
}
func UpdateSchedulesReport(w *sync.WaitGroup) {
fmt.Println("waiting...")
ch := time.After(5 * time.Second)
for {
select {
case <-ch:
fmt.Println("time is ", time.Now())
w.Done()
break
}
break
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment