Skip to content

Commit

Permalink
feat: do not stask a response if response interface and error are nil
Browse files Browse the repository at this point in the history
  • Loading branch information
proullon committed Apr 5, 2020
1 parent d322afe commit 3ca400d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions workerpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ var (
)

// JobFnc defines the job function executed by WorkerPool workers
//
// Note: if both response and error are nil, response will not be stacked
type JobFnc func(payload interface{}) (response interface{}, err error)

// OptFunc defines functionnal parameter to New() function
Expand Down Expand Up @@ -237,10 +239,12 @@ func (wp *WorkerPool) worker() {
wp.Done()
wp.tick()

wp.pushResponse(Response{
Body: body,
Err: err,
})
if body != nil || err != nil {
wp.pushResponse(Response{
Body: body,
Err: err,
})
}

if shouldExit := wp.evaluate(t, err); shouldExit {
return
Expand Down
2 changes: 1 addition & 1 deletion workerpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func TestAllIn(t *testing.T) {
job := &Job{}
wp, err := New(job.execute,
WithMaxWorker(1000),
WithEvaluationTime(2),
WithEvaluationTime(1),
WithSizePercentil(AllInSizesPercentil),
)

Expand Down

0 comments on commit 3ca400d

Please sign in to comment.