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.
v2ray-core/common/signal/close.go

36 lines
888 B

package signal
9 years ago
// CancelSignal is a signal passed to goroutine, in order to cancel the goroutine on demand.
type CancelSignal struct {
cancel chan struct{}
done chan struct{}
}
9 years ago
// NewCloseSignal creates a new CancelSignal.
func NewCloseSignal() *CancelSignal {
return &CancelSignal{
cancel: make(chan struct{}),
done: make(chan struct{}),
}
}
9 years ago
// Cancel signals the goroutine to stop.
func (this *CancelSignal) Cancel() {
close(this.cancel)
}
9 years ago
// WaitForCancel should be monitored by the goroutine for when to stop.
func (this *CancelSignal) WaitForCancel() <-chan struct{} {
return this.cancel
}
9 years ago
// Done signals the caller that the goroutine has completely finished.
func (this *CancelSignal) Done() {
close(this.done)
}
9 years ago
// WaitForDone is used by caller to wait for the goroutine finishes.
func (this *CancelSignal) WaitForDone() <-chan struct{} {
return this.done
}