Premier commit
This commit is contained in:
39
cmd/test/main.go
Normal file
39
cmd/test/main.go
Normal file
@ -0,0 +1,39 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
)
|
||||
|
||||
func prepareSouffle() {
|
||||
fmt.Println("Je prépare un souffle")
|
||||
}
|
||||
|
||||
func preparePatatoes() {
|
||||
fmt.Println("Je prépare des patates")
|
||||
}
|
||||
|
||||
func printTenIntsConcurrently(ch chan int) {
|
||||
var wg sync.WaitGroup
|
||||
for i := 0; i < 10; i++ {
|
||||
wg.Add(1)
|
||||
go printInt(i, &wg, &ch)
|
||||
}
|
||||
wg.Wait()
|
||||
close(ch)
|
||||
}
|
||||
|
||||
func printInt(i int, wg *sync.WaitGroup, ch *chan int) {
|
||||
defer wg.Done()
|
||||
*ch <- i
|
||||
}
|
||||
|
||||
func main() {
|
||||
ints := make(chan int)
|
||||
|
||||
go printTenIntsConcurrently(ints)
|
||||
|
||||
for i := range ints {
|
||||
fmt.Printf("%d\n", i)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user