awesome-patterns/playground/goroutine/basic_test.go
2018-09-07 21:11:24 +08:00

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 ...")
}