Mode:
Duration:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package main
import (
"fmt"
"time"
)
func worker(id int, jobs <-chan string) {
for job := range jobs {
fmt.Println("Worker", id, "processing", job)
for attempt := 1; attempt <= 3; attempt++ {
fmt.Println("Attempt", attempt, "for", job)
if attempt == 3 {
fmt.Println(job, "completed")
}
time.Sleep(time.Millisecond * 100)
}
}
}
func main() {
jobs := make(chan string, 3)
for i := 1; i <= 2; i++ {
go worker(i, jobs)
}
jobs <- "Send Email"
jobs <- "Generate Report"
jobs <- "Process Payment"
close(jobs)
time.Sleep(time.Second)
}Coding works best on desktop or with an external keyboard.