donechan.go 396 B

12345678910111213141516171819202122232425262728
  1. package syncx
  2. import (
  3. "sync"
  4. "github.com/tal-tech/go-zero/core/lang"
  5. )
  6. type DoneChan struct {
  7. done chan lang.PlaceholderType
  8. once sync.Once
  9. }
  10. func NewDoneChan() *DoneChan {
  11. return &DoneChan{
  12. done: make(chan lang.PlaceholderType),
  13. }
  14. }
  15. func (dc *DoneChan) Close() {
  16. dc.once.Do(func() {
  17. close(dc.done)
  18. })
  19. }
  20. func (dc *DoneChan) Done() chan lang.PlaceholderType {
  21. return dc.done
  22. }