1
0
Fork 0
main^2
Sebastian Steger 2025-08-20 11:36:42 +00:00
parent ff4a4b2023
commit c47b686210
1 changed files with 29 additions and 3 deletions

View File

@ -1,17 +1,43 @@
package main
func print(ci <-chan int) {
//TODO: implement
import (
"fmt"
"sync"
"time"
)
func printChannel(ci <-chan int, done chan<- bool) {
defer func() { done <- true }()
for i := range ci {
time.Sleep(100 * time.Millisecond)
fmt.Println(i)
}
}
func printWaitgroup(ci <-chan int, wg *sync.WaitGroup) {
defer func() { wg.Done() }()
for i := range ci {
time.Sleep(100 * time.Millisecond)
fmt.Println(i)
}
}
func main() {
c := make(chan int)
//done := make(chan bool)
//go printChannel(c, done)
wg := sync.WaitGroup{}
wg.Add(1)
go printWaitgroup(c, &wg)
c <- 1
c <- 2
c <- 3
close(c)
print(c)
//<-done
wg.Wait()
}