Comparing version 0.3.0 to 0.4.0
{ | ||
"name": "qyu", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "A general-purpose asynchronous job queue for Node.js", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -10,3 +10,3 @@ # Qyu | ||
(async () => { | ||
let q = new Qyu({concurrency: 3}); | ||
const q = new Qyu({concurrency: 3}); | ||
@@ -17,3 +17,3 @@ // Basic: | ||
// Extra options: | ||
q.add({priority: 7}, myAsyncFunction, arg1, arg2/*...*/)); | ||
q.add(myAsyncFunction, {priority: 7}, arg1, arg2 /*, ...*/)); | ||
@@ -23,3 +23,2 @@ // Doesn't matter if more jobs come around later, | ||
// for you based on your concurrency setting | ||
// as necessary: | ||
setTimeout(() => { | ||
@@ -26,0 +25,0 @@ for (let i=0; i<10; i++) { |
@@ -188,18 +188,15 @@ const | ||
add(/*...*/) { | ||
let job; | ||
add() { | ||
let job = arguments[0]; | ||
let opts; | ||
let firstIndexOfArgs; | ||
if (typeof arguments[0] === 'function') { | ||
job = arguments[0]; | ||
if (arguments[1] instanceof Object) { | ||
opts = arguments[1]; | ||
} else { | ||
opts = {args: null}; | ||
firstIndexOfArgs = 1; | ||
} else if (typeof arguments[1] === 'function') { | ||
opts = arguments[0]; | ||
job = arguments[1]; | ||
firstIndexOfArgs = 2; | ||
} | ||
opts.args = []; | ||
for (let i=firstIndexOfArgs, l=arguments.length; i<l; ++i) { | ||
opts.args.push(arguments[i]); | ||
if (arguments.length > 2) { | ||
opts.args = new Array(arguments.length - 2); | ||
for (let i=2, l=arguments.length; i<l; ++i) { | ||
opts.args[i] = arguments[i]; | ||
} | ||
} | ||
@@ -222,2 +219,3 @@ return this.enqueue(job, opts); | ||
this.isPaused = true; | ||
// TODO: return a promise that will resolve when current jobs that were already running will finish. Perhaps: return this.whenEmpty(); | ||
} | ||
@@ -224,0 +222,0 @@ |
@@ -18,15 +18,2 @@ const { Qyu, QyuError } = require('../index'); | ||
}); | ||
// it('...', () => { | ||
// let q = new Qyu({concurrency: 2}); | ||
// | ||
// let job1 = jest.fn(mockAsync); | ||
// let job2 = jest.fn(mockAsync); | ||
// | ||
// q(job1); | ||
// q(job2); | ||
// | ||
// expect(job1).toHaveBeenCalled(); | ||
// expect(job2).toHaveBeenCalled(); | ||
// }); | ||
}); | ||
@@ -58,2 +45,3 @@ | ||
// TODO: This test sometimes seems to experience some timing glitches that makes it fail; refactor it to be more reliable | ||
it('will delay in starting the next job queued, regardless of concurrency setting, by the specified amount of time if `rampUpTime` is more than zero', async () => { | ||
@@ -240,3 +228,3 @@ let rampUpTime = 100; | ||
q.add({timeout: 100}, () => called = true); | ||
q.add(() => called = true, {timeout: 100}); | ||
@@ -254,3 +242,3 @@ await q.whenEmpty(); | ||
try { | ||
await q.add({timeout: 100}, () => {}); | ||
await q.add(() => {}, {timeout: 100}); | ||
} | ||
@@ -275,6 +263,6 @@ catch (err) { | ||
q.add({priority: 2}, () => push('b')); | ||
q.add({priority: 3}, () => push('a')); | ||
q.add({priority: 1}, () => push('d')); | ||
q.add({priority: 2}, () => push('c')); | ||
q.add(() => push('b'), {priority: 2}); | ||
q.add(() => push('a'), {priority: 3}); | ||
q.add(() => push('d'), {priority: 1}); | ||
q.add(() => push('c'), {priority: 2}); | ||
@@ -281,0 +269,0 @@ await q.whenEmpty(); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
20357
485
86