Last active
October 10, 2018 14:55
-
-
Save g14a/ed63402a9282a595986e9b406dad95cb 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" | |
) | |
func main() { | |
ch := make(chan int) | |
var wg sync.WaitGroup | |
for i := 0; i < 10; i++ { | |
wg.Add(1) | |
go func(k int, wg *sync.WaitGroup) { | |
defer wg.Done() | |
ch <- k | |
}(i, &wg) | |
} | |
for { | |
i, more := <-ch | |
if more { | |
fmt.Println(i) | |
} else { | |
fmt.Println() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment