Improve helper concurrency (#1214)
This commit is contained in:
committed by
GitHub
parent
3751f50774
commit
7dfaa6c5b4
@ -301,6 +301,7 @@ class Helpers {
|
||||
|
||||
function semaphore () {
|
||||
if (running < concurrency) {
|
||||
running += 1
|
||||
return pImmediate(send)
|
||||
} else {
|
||||
return new Promise((resolve, reject) => {
|
||||
@ -311,13 +312,13 @@ class Helpers {
|
||||
|
||||
function send (msearchBody, callbacks) {
|
||||
/* istanbul ignore if */
|
||||
if (running >= concurrency) {
|
||||
if (running > concurrency) {
|
||||
throw new Error('Max concurrency reached')
|
||||
}
|
||||
running += 1
|
||||
msearchOperation(msearchBody, callbacks, () => {
|
||||
running -= 1
|
||||
if (resolveSemaphore) {
|
||||
running += 1
|
||||
resolveSemaphore(send)
|
||||
resolveSemaphore = null
|
||||
} else if (resolveFinish && running === 0) {
|
||||
@ -575,6 +576,7 @@ class Helpers {
|
||||
|
||||
function semaphore () {
|
||||
if (running < concurrency) {
|
||||
running += 1
|
||||
return pImmediate(send)
|
||||
} else {
|
||||
return new Promise((resolve, reject) => {
|
||||
@ -585,10 +587,9 @@ class Helpers {
|
||||
|
||||
function send (bulkBody) {
|
||||
/* istanbul ignore if */
|
||||
if (running >= concurrency) {
|
||||
if (running > concurrency) {
|
||||
throw new Error('Max concurrency reached')
|
||||
}
|
||||
running += 1
|
||||
bulkOperation(bulkBody, err => {
|
||||
running -= 1
|
||||
if (err) {
|
||||
@ -596,6 +597,7 @@ class Helpers {
|
||||
error = err
|
||||
}
|
||||
if (resolveSemaphore) {
|
||||
running += 1
|
||||
resolveSemaphore(send)
|
||||
resolveSemaphore = null
|
||||
} else if (resolveFinish && running === 0) {
|
||||
|
||||
Reference in New Issue
Block a user