diff --git a/.travis.yml b/.travis.yml index be99e0e..70c5eaa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,7 @@ go: - 1.13.x - 1.14.x - 1.15.x + - 1.16.x # Enable Go Modules env: diff --git a/examples/dynamic_size/go.mod b/examples/dynamic_size/go.mod index 4413459..453e8db 100644 --- a/examples/dynamic_size/go.mod +++ b/examples/dynamic_size/go.mod @@ -1,9 +1,9 @@ module github.com/alitto/pond/examples/dynamic_size -go 1.15 +go 1.16 require ( - github.com/alitto/pond v1.5.0 + github.com/alitto/pond v1.5.1 ) replace github.com/alitto/pond => ../../ diff --git a/examples/fixed_size/go.mod b/examples/fixed_size/go.mod index 8910c4d..973540f 100644 --- a/examples/fixed_size/go.mod +++ b/examples/fixed_size/go.mod @@ -1,9 +1,9 @@ module github.com/alitto/pond/examples/fixed_size -go 1.15 +go 1.16 require ( - github.com/alitto/pond v1.5.0 + github.com/alitto/pond v1.5.1 ) replace github.com/alitto/pond => ../../ diff --git a/examples/prometheus/go.mod b/examples/prometheus/go.mod index 0ac4656..500203e 100644 --- a/examples/prometheus/go.mod +++ b/examples/prometheus/go.mod @@ -1,9 +1,9 @@ module github.com/alitto/pond/examples/fixed_size -go 1.15 +go 1.16 require ( - github.com/alitto/pond v1.5.0 + github.com/alitto/pond v1.5.1 github.com/prometheus/client_golang v1.9.0 ) diff --git a/examples/task_group/go.mod b/examples/task_group/go.mod index 008ecad..d329728 100644 --- a/examples/task_group/go.mod +++ b/examples/task_group/go.mod @@ -1,9 +1,9 @@ module github.com/alitto/pond/examples/task_group -go 1.15 +go 1.16 require ( - github.com/alitto/pond v1.5.0 + github.com/alitto/pond v1.5.1 ) replace github.com/alitto/pond => ../../ diff --git a/go.mod b/go.mod index 7a4931c..b8b0057 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ module github.com/alitto/pond -go 1.15 +go 1.16 diff --git a/pond.go b/pond.go index aebc61c..10a80ea 100644 --- a/pond.go +++ b/pond.go @@ -211,13 +211,15 @@ func (p *WorkerPool) submit(task func(), canWaitForIdleWorker bool) (submitted b return false } - defer func() { - if submitted { - // Increment submitted task count - atomic.AddUint64(&p.submittedTaskCount, 1) + // Increment submitted and waiting task counters as soon as we receive a task + atomic.AddUint64(&p.submittedTaskCount, 1) + atomic.AddUint64(&p.waitingTaskCount, 1) - // Increment waiting task count - atomic.AddUint64(&p.waitingTaskCount, 1) + defer func() { + if !submitted { + // Task was not sumitted to the pool, decrement submitted and waiting task counters + atomic.AddUint64(&p.submittedTaskCount, ^uint64(0)) + atomic.AddUint64(&p.waitingTaskCount, ^uint64(0)) } }()