Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ed59ea1d0a | ||
|
|
9eec782920 | ||
|
|
f7d5b41aba | ||
|
|
7f494b3d57 |
@@ -1,8 +1,11 @@
|
|||||||
package grawt
|
package grawt
|
||||||
|
|
||||||
|
import "sync"
|
||||||
|
|
||||||
type CloseHandler struct {
|
type CloseHandler struct {
|
||||||
|
sync.Mutex
|
||||||
waiter *Waiter
|
waiter *Waiter
|
||||||
Quit chan bool
|
Quit chan struct{}
|
||||||
active bool
|
active bool
|
||||||
autoDone bool
|
autoDone bool
|
||||||
handlerFunc *func()
|
handlerFunc *func()
|
||||||
|
|||||||
16
waiter.go
16
waiter.go
@@ -16,11 +16,11 @@ type Waiter struct {
|
|||||||
|
|
||||||
func (w *Waiter) addHandler(f *func(), autoDone bool) *CloseHandler {
|
func (w *Waiter) addHandler(f *func(), autoDone bool) *CloseHandler {
|
||||||
ch := CloseHandler{
|
ch := CloseHandler{
|
||||||
w,
|
waiter: w,
|
||||||
make(chan bool, 1),
|
Quit: make(chan struct{}, 1),
|
||||||
true,
|
active: true,
|
||||||
autoDone,
|
autoDone: autoDone,
|
||||||
f,
|
handlerFunc: f,
|
||||||
}
|
}
|
||||||
w.waitGroup.Add(1)
|
w.waitGroup.Add(1)
|
||||||
w.closeHandlers = append(w.closeHandlers, &ch)
|
w.closeHandlers = append(w.closeHandlers, &ch)
|
||||||
@@ -32,11 +32,15 @@ func (w *Waiter) terminateHandler(h *CloseHandler, forceWaitGroupDone bool) {
|
|||||||
if h.handlerFunc != nil && *h.handlerFunc != nil {
|
if h.handlerFunc != nil && *h.handlerFunc != nil {
|
||||||
(*h.handlerFunc)()
|
(*h.handlerFunc)()
|
||||||
}
|
}
|
||||||
h.Quit <- true
|
h.Lock()
|
||||||
|
if h.active {
|
||||||
|
close(h.Quit)
|
||||||
|
}
|
||||||
if h.autoDone || forceWaitGroupDone {
|
if h.autoDone || forceWaitGroupDone {
|
||||||
w.waitGroup.Done()
|
w.waitGroup.Done()
|
||||||
}
|
}
|
||||||
h.active = false
|
h.active = false
|
||||||
|
h.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Waiter) AddCloseHandler(f func(), waitForChannel bool) *CloseHandler {
|
func (w *Waiter) AddCloseHandler(f func(), waitForChannel bool) *CloseHandler {
|
||||||
|
|||||||
Reference in New Issue
Block a user