Skip to content

Instantly share code, notes, and snippets.

@YashishDua
Last active November 19, 2018 10:07
Show Gist options
  • Save YashishDua/912de4562c315f3ff168ee32a7ecc0ee to your computer and use it in GitHub Desktop.
Save YashishDua/912de4562c315f3ff168ee32a7ecc0ee to your computer and use it in GitHub Desktop.
var mutex = &sync.Mutex{}
var wg sync.WaitGroup
func generateMessage(message string) {
//...
wg.Add(1)
go func() {
defer wg.Done()
printMessage(message)
} ()
wg.Wait()
}
func printMessage(resultMessage string) {
mutex.Lock()
defer mutex.Unlock()
// Internal Logic : Ignore
if IsTimeEnabled {
log.Println(resultMessage)
return
}
fmt.Println(resultMessage)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment