fn: common.WaitGroup improvements (#940)

* fn: common.WaitGroup improvements

*) Split the API into AddSession/DoneSession
*) Only wake up listeners when session count reaches zero.

* fn: WaitGroup go-routine blast test

* fn: test fix and rebase fixup
This commit is contained in:
Tolga Ceylan
2018-04-12 16:21:13 -07:00
committed by GitHub
parent e7dd095b92
commit 623aeb35b2
6 changed files with 94 additions and 56 deletions

View File

@@ -23,7 +23,7 @@ func (a *agent) asyncDequeue() {
for {
select {
case <-a.shutWg.Closer():
a.shutWg.AddSession(-1)
a.shutWg.DoneSession()
return
case <-a.resources.WaitAsyncResource(ctx):
// TODO we _could_ return a token here to reserve the ram so that there's
@@ -35,13 +35,13 @@ func (a *agent) asyncDequeue() {
// we think we can get a cookie now, so go get a cookie
select {
case <-a.shutWg.Closer():
a.shutWg.AddSession(-1)
a.shutWg.DoneSession()
return
case model, ok := <-a.asyncChew(ctx):
if ok {
go func(model *models.Call) {
a.asyncRun(ctx, model)
a.shutWg.AddSession(-1)
a.shutWg.DoneSession()
}(model)
// WARNING: tricky. We reserve another session for next iteration of the loop