package main
import (
"fmt"
"time"
)
var m map[int]chan bool
func loop(i int) {
n := 0
for {
select {
case <-m[i]:
break
default:
fmt.Println(n)
time.Sleep(500 * time.Millisecond)
n++
}
}
}
func Rt() {
m[1] = make(chan bool)
go loop(1);
time.Sleep(2 * time.Second)
m[1] <- true
}
func main() {
q := make(chan bool)
m = make(map[int]chan bool)
Rt()
<-q
}
func loop(i int) {
n := 0
loop:
for {
select {
case <-m[i]:
break loop
default:
fmt.Println(n)
time.Sleep(500 * time.Millisecond)
n++
}
}
}
func loop() {
n := 0
c := time.After(2*time.Second)
loop:
for {
select {
case <-c:
break loop
default:
fmt.Println(n)
time.Sleep(500 * time.Millisecond)
n++
}
}
}