Created
September 15, 2022 12:47
-
-
Save bechampion/8d59cac968487edd2c6771e21efef0d9 to your computer and use it in GitHub Desktop.
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" | |
"time" | |
) | |
func main() { | |
cc := make(chan int) | |
var wg sync.WaitGroup | |
wg.Add(2) | |
go func(cc chan int) { | |
defer wg.Done() | |
for i := 0; i <= 10; i++ { | |
fmt.Printf("job starting %d\n", i) | |
time.Sleep(1 * time.Second) | |
cc <- i | |
fmt.Printf("job ending%d\n", i) | |
} | |
}(cc) | |
go func(cc chan int) { | |
defer wg.Done() | |
for { | |
select { | |
case msg := <-cc: | |
fmt.Println(msg) | |
default: | |
} | |
} | |
}(cc) | |
wg.Wait() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment