go-zero/core/syncx/donechan.go

29 lines
396 B
Go
Raw Normal View History

2020-07-26 17:09:05 +08:00
package syncx
import (
"sync"
2020-08-08 16:40:10 +08:00
"github.com/tal-tech/go-zero/core/lang"
2020-07-26 17:09:05 +08:00
)
type DoneChan struct {
done chan lang.PlaceholderType
once sync.Once
}
func NewDoneChan() *DoneChan {
return &DoneChan{
done: make(chan lang.PlaceholderType),
}
}
func (dc *DoneChan) Close() {
dc.once.Do(func() {
close(dc.done)
})
}
func (dc *DoneChan) Done() chan lang.PlaceholderType {
return dc.done
}