Go code
jobs := make(chan int)
results := make(chan int)
go func() {
job := <-jobs
results <- job * 2
}()
jobs <- 5
fmt.Println(<-results)Line-by-line explanation
- Two typed channels are created.
- The worker waits for one job.
- It doubles and sends a result.
- Main sends 5.
- Main receives and displays 10.
Expected output
10This is the expected result.