donechan_test.go 427 B

123456789101112131415161718192021222324252627282930313233
  1. package syncx
  2. import (
  3. "sync"
  4. "testing"
  5. )
  6. func TestDoneChanClose(t *testing.T) {
  7. doneChan := NewDoneChan()
  8. for i := 0; i < 5; i++ {
  9. doneChan.Close()
  10. }
  11. }
  12. func TestDoneChanDone(t *testing.T) {
  13. var waitGroup sync.WaitGroup
  14. doneChan := NewDoneChan()
  15. waitGroup.Add(1)
  16. go func() {
  17. select {
  18. case <-doneChan.Done():
  19. waitGroup.Done()
  20. }
  21. }()
  22. for i := 0; i < 5; i++ {
  23. doneChan.Close()
  24. }
  25. waitGroup.Wait()
  26. }