Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7f494b3d57 | ||
|
|
ac0f979ef9 |
@@ -10,5 +10,6 @@ waiter.AddCloseHandler(func() {
|
|||||||
nacl.FinalizeStan()
|
nacl.FinalizeStan()
|
||||||
}, false)
|
}, false)
|
||||||
|
|
||||||
waiter.Wait(true)
|
// blocking wait, if no need to block (with http server, for example), you can omit .Wait() call
|
||||||
|
waiter.Wait()
|
||||||
```
|
```
|
||||||
@@ -2,7 +2,7 @@ package grawt
|
|||||||
|
|
||||||
type CloseHandler struct {
|
type CloseHandler struct {
|
||||||
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
@@ -17,7 +17,7 @@ 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,
|
w,
|
||||||
make(chan bool, 1),
|
make(chan struct{}, 1),
|
||||||
true,
|
true,
|
||||||
autoDone,
|
autoDone,
|
||||||
f,
|
f,
|
||||||
@@ -32,7 +32,7 @@ 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.Quit <- struct{}{}
|
||||||
if h.autoDone || forceWaitGroupDone {
|
if h.autoDone || forceWaitGroupDone {
|
||||||
w.waitGroup.Done()
|
w.waitGroup.Done()
|
||||||
}
|
}
|
||||||
@@ -63,12 +63,10 @@ func (w *Waiter) Halt(err error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Waiter) Wait(blockingMode bool) {
|
func (w *Waiter) Wait() {
|
||||||
w.blockingMode = blockingMode
|
w.blockingMode = true
|
||||||
if blockingMode {
|
log.Info("Waiting...")
|
||||||
log.Info("Waiting...")
|
w.waitGroup.Wait()
|
||||||
w.waitGroup.Wait()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Waiter) onSignal(sig os.Signal) {
|
func (w *Waiter) onSignal(sig os.Signal) {
|
||||||
@@ -78,7 +76,7 @@ func (w *Waiter) onSignal(sig os.Signal) {
|
|||||||
|
|
||||||
func NewWaiter() *Waiter {
|
func NewWaiter() *Waiter {
|
||||||
w := Waiter{
|
w := Waiter{
|
||||||
true,
|
false,
|
||||||
sync.WaitGroup{},
|
sync.WaitGroup{},
|
||||||
make([]*CloseHandler, 0),
|
make([]*CloseHandler, 0),
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user