From dfdd6b05b660d0f54fe2abe1e2bfab6b1e8608fa Mon Sep 17 00:00:00 2001 From: Levi Roberts Date: Sun, 31 May 2020 10:44:52 -0500 Subject: [PATCH] Added ability to start a job immediately Closes #71 --- index.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 990d1d1..9e04c22 100644 --- a/index.js +++ b/index.js @@ -46,6 +46,12 @@ Queue.prototype.reverse = function () { return this } +Queue.prototype.pushImmediate = function () { + Array.prototype.unshift.apply(this.jobs, arguments) + this.start(null, true) + return this +} + var arrayAddMethods = [ 'push', 'unshift', @@ -75,8 +81,10 @@ Queue.prototype.start = function (cb) { this.running = true - if (this.pending >= this.concurrency) { - return + if (!startImmediate) { + if (this.pending >= this.concurrency) { + return + } } if (this.jobs.length === 0) {