diff --git a/example/index.js b/example/index.js index 817f2fe..3f56059 100644 --- a/example/index.js +++ b/example/index.js @@ -69,6 +69,17 @@ function extraSlowJob (cb) { extraSlowJob.timeout = 500 q.push(extraSlowJob) +// jobs can also opt-out of the timeout altogether +function superSlowJob (cb) { + setTimeout(function () { + console.log('super slow job finished') + cb() + }, 1000) +} + +superSlowJob.timeout = null +q.push(superSlowJob) + // get notified when jobs complete q.on('success', function (result, job) { console.log('job finished processing:', job.toString().replace(/\n/g, '')) diff --git a/index.js b/index.js index bd65940..990d1d1 100644 --- a/index.js +++ b/index.js @@ -93,7 +93,7 @@ Queue.prototype.start = function (cb) { var timeoutId = null var didTimeout = false var resultIndex = null - var timeout = job.timeout || this.timeout + var timeout = job.hasOwnProperty('timeout') ? job.timeout : this.timeout function next (err, result) { if (once && self.session === session) { diff --git a/readme.md b/readme.md index c249d34..687485f 100644 --- a/readme.md +++ b/readme.md @@ -87,6 +87,17 @@ function extraSlowJob (cb) { extraSlowJob.timeout = 500 q.push(extraSlowJob) +// jobs can also opt-out of the timeout altogether +function superSlowJob (cb) { + setTimeout(function () { + console.log('super slow job finished') + cb() + }, 1000) +} + +superSlowJob.timeout = null +q.push(superSlowJob) + // get notified when jobs complete q.on('success', function (result, job) { console.log('job finished processing:', job.toString().replace(/\n/g, '')) diff --git a/test/timeout.js b/test/timeout.js index cda9acd..48bfa93 100644 --- a/test/timeout.js +++ b/test/timeout.js @@ -70,6 +70,32 @@ tape('job timeout', function (t) { q.start() }) +tape('job-based opt-out of timeout', function (t) { + t.plan(1) + + var timeouts = 0 + var q = queue({ timeout: 5 }) + function wontTimeout (cb) { + setTimeout(cb, 8) + } + + wontTimeout.timeout = null + + q.on('timeout', function (next) { + t.fail('Job should not have timed-out') + timeouts++ + next() + }) + + q.on('end', function () { + t.equal(timeouts, 0) + }) + + q.push(wontTimeout) + + q.start() +}) + tape('timeout auto-continue', function (t) { t.plan(3)