Skip to content

Commit

Permalink
Update exports to play nice with ts 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
cmseaton42 committed Jan 13, 2020
1 parent 568450e commit e12620f
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 24 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const prioritize = (obj1, obj2) => {
Now, we can initialize a new _TaskEasy_ instance.

```js
const TaskEasy = require("task-easy");
const { TaskEasy } = require("task-easy");

const max_tasks = 200; // How many tasks will we allow to be queued at a time (defaults to 100)
const queue = new TaskEasy(prioritize, max_tasks);
Expand Down Expand Up @@ -122,7 +122,7 @@ const task5 = queue
## Now with _Typescript_

```typescript
import TaskEasy from "task-easy";
import { TaskEasy } from "task-easy";

// Define interface for priority
// objects to be used in the
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "task-easy",
"version": "0.2.1",
"version": "1.0.0",
"description": "A simple, customizable, and lightweight priority queue for promise based tasks.",
"main": "./src/index.js",
"types": "./src/index.d.ts",
Expand Down
5 changes: 1 addition & 4 deletions src/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
// Per Module-class.d.ts documentation
export = TaskEasy;

// Task Easy Class
declare class TaskEasy<C> {
export declare class TaskEasy<C> {
constructor(compare_func: (ob1: C, obj2: C) => boolean, max_queue_size?: number);
schedule<P, T extends TaskEasy.Task<P>>(task: T, args: TaskEasy.Arguments<T>, priority_obj: C): Promise<P>;
}
Expand Down
22 changes: 7 additions & 15 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ class TaskEasy {
);

if (typeof max_queue_size !== "number")
throw new Error(
`Task Easy Max Queue Size must be of Type <Number> instead got ${typeof max_queue_size}`
);
throw new Error(`Task Easy Max Queue Size must be of Type <Number> instead got ${typeof max_queue_size}`);

if (max_queue_size <= 0) throw new Error("Task Easy Max Queue Size must be greater than 0");

Expand All @@ -38,14 +36,10 @@ class TaskEasy {
schedule(task, args, priority_obj) {
if (typeof task !== "function")
throw new Error(`Scheduler Task must be of Type <function> instead got ${typeof task}`);
if (!Array.isArray(args))
throw new Error(`Scheduler args must be of Type <Array> instead got ${typeof args}`);
if (!Array.isArray(args)) throw new Error(`Scheduler args must be of Type <Array> instead got ${typeof args}`);
if (typeof priority_obj !== "object")
throw new Error(
`Scheduler Task must be of Type <Object> instead got ${typeof priority_obj}`
);
if (this.tasks.length >= this.max)
throw new Error(`Micro Queue is already full at size of ${this.max}!!!`);
throw new Error(`Scheduler Task must be of Type <Object> instead got ${typeof priority_obj}`);
if (this.tasks.length >= this.max) throw new Error(`Micro Queue is already full at size of ${this.max}!!!`);

// return Promise to Caller
return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -89,10 +83,8 @@ class TaskEasy {

let swap = index;

if (l < size && compare(this.tasks[l].priority_obj, this.tasks[swap].priority_obj))
swap = l;
if (r < size && compare(this.tasks[r].priority_obj, this.tasks[swap].priority_obj))
swap = r;
if (l < size && compare(this.tasks[l].priority_obj, this.tasks[swap].priority_obj)) swap = l;
if (r < size && compare(this.tasks[r].priority_obj, this.tasks[swap].priority_obj)) swap = r;

if (swap !== index) {
this._swap(swap, index);
Expand Down Expand Up @@ -140,4 +132,4 @@ class TaskEasy {
}
}

module.exports = TaskEasy;
module.exports = { TaskEasy };
2 changes: 1 addition & 1 deletion src/task-easy.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const TaskEasy = require("./index");
const { TaskEasy } = require("./index");

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

Expand Down

0 comments on commit e12620f

Please sign in to comment.