Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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)
- }
Add Comment
Please, Sign In to add comment