You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"sync"
|
|
)
|
|
|
|
func main() {
|
|
ch := make(chan int, 10)
|
|
wg := sync.WaitGroup{}
|
|
wg.Add(1)
|
|
go func() {
|
|
defer wg.Done()
|
|
for i := 0; i < 10; i++ {
|
|
ch <- i
|
|
fmt.Println(i)
|
|
}
|
|
close(ch)
|
|
}()
|
|
wg.Wait()
|
|
for n := range ch {
|
|
fmt.Println("Read:", n)
|
|
}
|
|
}
|