1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2026-01-05 16:55:27 -05:00

remove cancel signal

This commit is contained in:
Darien Raymond
2017-02-13 23:03:42 +01:00
parent 48639ddb98
commit 6d446f57f7
2 changed files with 19 additions and 72 deletions

View File

@@ -1,51 +0,0 @@
package signal
import (
"sync"
)
// CancelSignal is a signal passed to goroutine, in order to cancel the goroutine on demand.
type CancelSignal struct {
cancel chan struct{}
done sync.WaitGroup
}
// NewCloseSignal creates a new CancelSignal.
func NewCloseSignal() *CancelSignal {
return &CancelSignal{
cancel: make(chan struct{}),
}
}
func (v *CancelSignal) WaitThread() {
v.done.Add(1)
}
// Cancel signals the goroutine to stop.
func (v *CancelSignal) Cancel() {
close(v.cancel)
}
func (v *CancelSignal) Cancelled() bool {
select {
case <-v.cancel:
return true
default:
return false
}
}
// WaitForCancel should be monitored by the goroutine for when to stop.
func (v *CancelSignal) WaitForCancel() <-chan struct{} {
return v.cancel
}
// FinishThread signals that current goroutine has finished.
func (v *CancelSignal) FinishThread() {
v.done.Done()
}
// WaitForDone is used by caller to wait for the goroutine finishes.
func (v *CancelSignal) WaitForDone() {
v.done.Wait()
}