mirror of https://github.com/tidwall/tile38.git
Merge pull request #437 from tidwall/issue-428
Fixed clients blocking while webook sending
This commit is contained in:
commit
cf57b775ec
|
@ -462,6 +462,7 @@ type Hook struct {
|
||||||
epm *endpoint.Manager
|
epm *endpoint.Manager
|
||||||
expires time.Time
|
expires time.Time
|
||||||
counter *aint // counter that grows when a message was sent
|
counter *aint // counter that grows when a message was sent
|
||||||
|
sig int
|
||||||
}
|
}
|
||||||
|
|
||||||
// Expires returns when the hook expires. Required by the expire.Item interface.
|
// Expires returns when the hook expires. Required by the expire.Item interface.
|
||||||
|
@ -561,6 +562,7 @@ func (h *Hook) Signal() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
h.cond.L.Lock()
|
h.cond.L.Lock()
|
||||||
|
h.sig++
|
||||||
h.cond.Broadcast()
|
h.cond.Broadcast()
|
||||||
h.cond.L.Unlock()
|
h.cond.L.Unlock()
|
||||||
}
|
}
|
||||||
|
@ -568,23 +570,32 @@ func (h *Hook) Signal() {
|
||||||
// the manager is a forever loop that calls proc whenever there's a signal.
|
// the manager is a forever loop that calls proc whenever there's a signal.
|
||||||
// it ends when the "closed" flag is set.
|
// it ends when the "closed" flag is set.
|
||||||
func (h *Hook) manager() {
|
func (h *Hook) manager() {
|
||||||
|
// lock the hook to waiting on signals
|
||||||
|
h.cond.L.Lock()
|
||||||
|
defer h.cond.L.Unlock()
|
||||||
|
var sig int
|
||||||
for {
|
for {
|
||||||
h.cond.L.Lock()
|
if h.closed {
|
||||||
for {
|
// the hook has closed, end manager
|
||||||
if h.closed {
|
return
|
||||||
h.cond.L.Unlock()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if h.proc() {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
h.cond.L.Unlock()
|
|
||||||
// proc failed. wait half a second and try again
|
|
||||||
time.Sleep(time.Second / 2)
|
|
||||||
h.cond.L.Lock()
|
|
||||||
}
|
}
|
||||||
|
sig = h.sig
|
||||||
|
// unlock/logk the hook and send outgoing messages
|
||||||
|
if !func() bool {
|
||||||
|
h.cond.L.Unlock()
|
||||||
|
defer h.cond.L.Lock()
|
||||||
|
return h.proc()
|
||||||
|
}() {
|
||||||
|
// a send failed, try again in a moment
|
||||||
|
time.Sleep(time.Second / 2)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if sig != h.sig {
|
||||||
|
// there was another incoming signal
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// wait on signal
|
||||||
h.cond.Wait()
|
h.cond.Wait()
|
||||||
h.cond.L.Unlock()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue