Created
July 23, 2019 06:14
-
-
Save chaudharisuresh997/055a56f81c8756b534adc81796fdb0c0 to your computer and use it in GitHub Desktop.
Channel and Waitgroup example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"sync" | |
) | |
//Workgroup example | |
func tie(wg *sync.WaitGroup) { | |
fmt.Println("Shiv") | |
wg.Done() | |
} | |
//channel | |
func chanFunc(ch chan int) { | |
fmt.Println("chValue") | |
defer close(ch) | |
ch <- 1 | |
} | |
func main() { | |
// var wg sync.WaitGroup | |
// wg.Add(1) | |
// go tie(&wg) | |
// wg.Wait() | |
//channel | |
ch := make(chan int) | |
go chanFunc(ch) | |
fmt.Println(<-ch) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment