awesome-patterns/playground/goroutine/basic_test.go

26 lines
392 B
Go
Raw Permalink Normal View History

2018-09-07 16:11:24 +03:00
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 ...")
}