Comparing version 0.2.1 to 0.3.0
{ | ||
"name": "qyu", | ||
"version": "0.2.1", | ||
"version": "0.3.0", | ||
"description": "A general-purpose asynchronous job queue for Node.js", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -17,13 +17,17 @@ const | ||
const makeQyuProxy = inst => { | ||
const makeQyuProxy = q => { | ||
return new Proxy( | ||
function() { | ||
return inst.add(...arguments); | ||
if (arguments[0] instanceof Array) { | ||
return q.map(arguments[0], arguments[1], arguments[2]); | ||
} else { | ||
return q.add(arguments[0], arguments[1]); | ||
} | ||
}, | ||
{ | ||
get: (target, prop, receiver) => { | ||
return inst[prop]; | ||
return q[prop]; | ||
}, | ||
set: (obj, prop, value) => { | ||
inst[prop] = value; | ||
q[prop] = value; | ||
return true; | ||
@@ -35,3 +39,2 @@ } | ||
class Qyu { | ||
@@ -207,8 +210,11 @@ constructor(opts={}, job=null, jobOpts={}) { | ||
map(arr, fn) { | ||
return Promise.all( | ||
arr.map((v, k) => { | ||
return this.add(() => fn(v, k)); | ||
}) | ||
); | ||
map(iterator, fn) { | ||
let counter = 0; | ||
let promises = []; | ||
for (let item of iterator) { | ||
promises.push( | ||
this.add(() => fn(item, counter++)) | ||
); | ||
} | ||
return Promise.all(promises); | ||
} | ||
@@ -215,0 +221,0 @@ |
@@ -14,3 +14,2 @@ const { Qyu, QyuError } = require('../index'); | ||
describe('When A Qyu instance is invoked as a function', () => { | ||
@@ -20,2 +19,15 @@ it("should behave exactly like calling it's `add` method", () => { | ||
}); | ||
// 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(); | ||
// }); | ||
}); | ||
@@ -148,2 +160,12 @@ | ||
}); | ||
// it('...', () => { | ||
// let q = new Qyu({concurrency: 3}); | ||
// | ||
// q.map(['a', 'b', 'c'], async (v, k) => { | ||
// console.log('START', k, JSON.stringify(v), Date.now()); | ||
// await mockAsync(null, 1000); | ||
// console.log('END', k, JSON.stringify(v), Date.now()); | ||
// }); | ||
// }); | ||
}); | ||
@@ -150,0 +172,0 @@ |
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
20558
498