()
| 686 | this.concurrency = concurrency; |
| 687 | |
| 688 | const jobTick = () => { |
| 689 | if (this.paused) { |
| 690 | this.queued -= 1; |
| 691 | return; |
| 692 | } |
| 693 | |
| 694 | // invariant: in this code path, this.running < this.concurrency, always |
| 695 | // after spoolup, this.running + this.queued === this.concurrency |
| 696 | finally_( |
| 697 | this._getNextJob().then((job) => { |
| 698 | // We're shutting down. |
| 699 | if (this.paused) { |
| 700 | // This job will get picked up later as a stalled job if we happen |
| 701 | // to get here. We can't easily process this job because at this |
| 702 | // point Queue#close has already captured the activeJobs set in a |
| 703 | // Promise.all call, and we'd prefer to delay a job than |
| 704 | // half-process it. |
| 705 | this.queued -= 1; |
| 706 | return; |
| 707 | } |
| 708 | |
| 709 | this.running += 1; |
| 710 | this.queued -= 1; |
| 711 | if (this.running + this.queued < this.concurrency) { |
| 712 | this.queued += 1; |
| 713 | setImmediate(jobTick); |
| 714 | } |
| 715 | |
| 716 | if (!job) { |
| 717 | // Per comment in Queue#_waitForJob, this branch is possible when |
| 718 | // the job is removed before processing can take place, but after |
| 719 | // being initially acquired. |
| 720 | return; |
| 721 | } |
| 722 | |
| 723 | return this._runJob(job).then((results) => { |
| 724 | this.running -= 1; |
| 725 | this.queued += 1; |
| 726 | |
| 727 | /* istanbul ignore else */ |
| 728 | if (results) { |
| 729 | const status = results[0], |
| 730 | result = results[1]; |
| 731 | this.emit(status, job, result); |
| 732 | |
| 733 | // Workaround for #184: emit failed event for backwards |
| 734 | // compatibility while affording for a separate event that |
| 735 | // identifies the final failure. |
| 736 | const emitExtra = |
| 737 | status === 'retrying' |
| 738 | ? 'failed' |
| 739 | : status === 'failed' |
| 740 | ? 'failed:fatal' |
| 741 | : null; |
| 742 | if (emitExtra) this.emit(emitExtra, job, result); |
| 743 | } |
| 744 | }, this._emitErrorAfterTick); |
| 745 | }), |
nothing calls this directly
no test coverage detected