1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-12-29 05:25:21 -05:00
This commit is contained in:
Darien Raymond
2018-02-11 23:28:42 +01:00
parent 997c852be8
commit 20fc4950b2
4 changed files with 29 additions and 5 deletions

View File

@@ -4,18 +4,21 @@ import (
"sync"
)
// Done is an utility for notifications of something being done.
type Done struct {
access sync.Mutex
c chan struct{}
closed bool
}
// NewDone returns a new Done.
func NewDone() *Done {
return &Done{
c: make(chan struct{}),
}
}
// Done returns true if Close() is called.
func (d *Done) Done() bool {
select {
case <-d.c:
@@ -25,14 +28,17 @@ func (d *Done) Done() bool {
}
}
// C returns a channel for waiting for done.
func (d *Done) C() chan struct{} {
return d.c
}
// Wait blocks until Close() is called.
func (d *Done) Wait() {
<-d.c
}
// Close marks this Done 'done'. This method may be called mutliple times. All calls after first call will have no effect on its status.
func (d *Done) Close() error {
d.access.Lock()
defer d.access.Unlock()