fn: resource and slot cancel and broadcast improvements (#696)

* fn: resource and slot cancel and broadcast improvements

*) Context argument does not wake up the waiters correctly upon
cancellation/timeout.
*) Avoid unnecessary broadcasts in slot and resource.

* fn: limit scope of context in resource/slot calls in agent
This commit is contained in:
Tolga Ceylan
2018-01-18 13:43:56 -08:00
committed by GitHub
parent c9e995292c
commit 2f0de2b574
6 changed files with 89 additions and 51 deletions

View File

@@ -16,13 +16,13 @@ func (a *agent) asyncDequeue() {
defer cancel()
for {
ch, cancelWait := a.resources.WaitAsyncResource()
ctxResource, cancelResource := context.WithCancel(context.Background())
select {
case <-a.shutdown:
cancelWait()
cancelResource()
return
case <-ch:
cancelWait()
case <-a.resources.WaitAsyncResource(ctxResource):
cancelResource()
// TODO we _could_ return a token here to reserve the ram so that there's
// not a race between here and Submit but we're single threaded
// dequeueing and retries handled gracefully inside of Submit if we run