mirror of
https://github.com/crazybber/awesome-patterns.git
synced 2024-11-25 06:16:03 +03:00
26 lines
392 B
Go
26 lines
392 B
Go
|
package goroutine
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"testing"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
func TestOneGopher(t *testing.T) {
|
||
|
go sleepyGopher(1)
|
||
|
time.Sleep(3 * time.Second)
|
||
|
}
|
||
|
|
||
|
func TestFiveGopher(t *testing.T) {
|
||
|
c := make(chan int)
|
||
|
for i := 0; i < 5; i++ {
|
||
|
go sleepyGopherWithChan(i, c)
|
||
|
}
|
||
|
time.Sleep(3 * time.Second)
|
||
|
}
|
||
|
|
||
|
func sleepyGopher(id int) {
|
||
|
time.Sleep(2 * time.Second)
|
||
|
fmt.Println("... ", id, " snore ...")
|
||
|
}
|