Go: Common Deadlocks I | Solution 2

You're reading from a channel while nobody is writing to it. This will block the reader. The goroutine writing to it is never spawned. You need to move the reads (see code in bold).

package main

import (
	"fmt"
	"sync"
)

func main() {
	var wg sync.WaitGroup

	ch := make(chan int)

	wg.Add(1)

	go func() {
		for i := 0; i < 10; i++ {
			ch <- i
		}
		close(ch)
		wg.Done()
	}()
	
	for v := range ch {
		fmt.Println(v)
	}

	wg.Wait()
}