Skip to content

Commit

Permalink
Fix small bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
cmseaton42 committed Mar 23, 2018
1 parent b1d908e commit c85d1b4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 17 deletions.
4 changes: 2 additions & 2 deletions micro-queue/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @param {Function} compare_func - Function to handle comparison objects passed to Scheduler
* @param {Number} [max_queue_size=100] Max number of tasks allowed in queue
*/
class Micro {
class MicroQueue {
constructor(compare_func, max_queue_size = 100) {
this.tasks = [];
this.taskRunning = false;
Expand Down Expand Up @@ -139,4 +139,4 @@ class Micro {
}
}

module.exports = Micro;
module.exports = MicroQueue;
21 changes: 7 additions & 14 deletions micro-queue/micro.spec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const Micro = require("./index");
const MicroQueue = require("./index");

const delay = ms => new Promise(resolve => setTimeout(resolve, ms));

describe("Micro Worker", () => {
describe("New Instance", () => {
it("Rejects Improper Constructor Arguments", () => {
const fn = (arg, max) => () => new Micro(arg, max);
const fn = (arg, max) => () => new MicroQueue(arg, max);

expect(fn()).toThrow();
expect(fn("hello", 6)).toThrow();
Expand Down Expand Up @@ -36,7 +36,7 @@ describe("Micro Worker", () => {
});
}

q = new Micro(compare);
q = new MicroQueue(compare);
q.tasks = arr;
});

Expand All @@ -60,7 +60,7 @@ describe("Micro Worker", () => {
}, ms);
});

const q = new Micro(compare);
const q = new MicroQueue(compare);
const p1 = q.schedule(delayReturn, [50], { value: 1 });
const p2 = q.schedule(delayReturn, [60], { value: 1 });
const p3 = q.schedule(delayReturn, [70], { value: 1 });
Expand All @@ -80,7 +80,7 @@ describe("Micro Worker", () => {
}, ms);
});

const q = new Micro(compare);
const q = new MicroQueue(compare);
const res = [];
const p1 = q.schedule(delayReturn, [100], { value: 1, id: 1 }).then(n => res.push(n));
const p2 = q.schedule(delayReturn, [110], { value: 1, id: 2 }).then(n => res.push(n));
Expand Down Expand Up @@ -109,18 +109,11 @@ describe("Micro Worker", () => {
if (obj1.value === obj2.value) return obj1.id < obj2.id;
return obj1.value >= obj2.value;
};

for (let i = 0; i < 15; i++) {
arr.push({ task: delay, args: [100 * i], priority_obj: { value: i } });
}

q = new Micro(compare);
q.tasks = arr;
});

describe("Scheduler", () => {
it("It Rejects Bad Args", () => {
const q = new Micro(compare);
const q = new MicroQueue(compare);
const fn = (func, args, obj) => () => {
q.schedule(func, args, obj);
};
Expand All @@ -133,7 +126,7 @@ describe("Micro Worker", () => {
});

it("Throws if too many tasks queued", () => {
const q = new Micro(compare, 10);
const q = new MicroQueue(compare, 10);

const fn = () => {
for (let i = 0; i < 15; i++) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "micro-queue",
"version": "0.1.0",
"description": "A lightwieght promise-based priority task/job queue.",
"main": "./micro/index.js",
"main": "./micro-queue/index.js",
"scripts": {
"test":
"npm run lint && jest && npm run test:coverage && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
Expand Down

0 comments on commit c85d1b4

Please sign in to comment.