You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
719 B
42 lines
719 B
3 years ago
|
package tdsync
|
||
|
|
||
|
import "sync"
|
||
|
|
||
|
// ResetReady is like Ready, but can be Reset.
|
||
|
type ResetReady struct {
|
||
|
ready Ready
|
||
|
lock sync.Mutex
|
||
|
}
|
||
|
|
||
|
// NewResetReady creates new ResetReady.
|
||
|
func NewResetReady() *ResetReady {
|
||
|
return &ResetReady{
|
||
|
ready: Ready{
|
||
|
wait: make(chan struct{}),
|
||
|
},
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Reset resets underlying Ready.
|
||
|
func (r *ResetReady) Reset() {
|
||
|
r.lock.Lock()
|
||
|
r.ready.Signal()
|
||
|
r.ready.reset()
|
||
|
r.lock.Unlock()
|
||
|
}
|
||
|
|
||
|
// Signal sends ready signal.
|
||
|
// Can be called multiple times.
|
||
|
func (r *ResetReady) Signal() {
|
||
|
r.lock.Lock()
|
||
|
r.ready.Signal()
|
||
|
r.lock.Unlock()
|
||
|
}
|
||
|
|
||
|
// Ready returns waiting channel.
|
||
|
func (r *ResetReady) Ready() <-chan struct{} {
|
||
|
r.lock.Lock()
|
||
|
defer r.lock.Unlock()
|
||
|
return r.ready.Ready()
|
||
|
}
|