31 lines
388 B
Go
31 lines
388 B
Go
package pkg
|
|
|
|
import (
|
|
"sync"
|
|
"testing"
|
|
)
|
|
|
|
func TestChan(t *testing.T) {
|
|
t.Run("close", func(t *testing.T) {
|
|
ch := NewSingleChan()
|
|
wg := sync.WaitGroup{}
|
|
wg.Add(2)
|
|
go func() {
|
|
ch.Send()
|
|
//ch.Send()
|
|
close(ch)
|
|
tmp, ok := <-ch
|
|
t.Log("after close", tmp, ok)
|
|
wg.Done()
|
|
}()
|
|
|
|
go func() {
|
|
tmp, ok := <-ch
|
|
t.Log(tmp, ok)
|
|
wg.Done()
|
|
}()
|
|
|
|
wg.Wait()
|
|
})
|
|
}
|