[
  {
    "path": ".eslintignore",
    "content": "\nnode_modules/**\ncoverage/**\nscripts/**"
  },
  {
    "path": ".eslintrc.js",
    "content": "module.exports = {\n    env: {\n        \"jest/globals\": true,\n        es6: true,\n        node: true\n    },\n    extends: [\"eslint:recommended\"],\n    parserOptions: {\n        ecmaVersion: 8,\n        sourceType: \"module\",\n        ecmaFeatures: {\n            jsx: true,\n            experimentalObjectRestSpread: true\n        }\n    },\n    rules: {\n        indent: [\"error\", 4],\n        \"no-console\": 0,\n        quotes: [\"error\", \"double\"],\n        semi: [\"error\", \"always\"],\n        \"jest/no-disabled-tests\": \"warn\",\n        \"jest/no-focused-tests\": \"error\",\n        \"jest/no-identical-title\": \"error\",\n        \"jest/prefer-to-have-length\": \"warn\",\n        \"jest/valid-expect\": \"error\"\n    },\n    plugins: [\"jest\"]\n};\n"
  },
  {
    "path": ".gitignore",
    "content": "/node_modules/\n\n# Ignore Jest Coverage Reports\n/coverage\n\n/assets"
  },
  {
    "path": ".npmignore",
    "content": "**/*.spec.js\n/coverage\n/assets\n**/__snapshots__"
  },
  {
    "path": ".travis.yml",
    "content": "language: node_js\nnode_js:\n  - \"node\"\nnotifications:\n  webhooks:\n    urls:\n      - https://webhooks.gitter.im/e/7cce00f2d081132a34c2\n    on_success: change  # options: [always|never|change] default: always\n    on_failure: always  # options: [always|never|change] default: always\n    on_start: never     # options: [always|never|change] default: always"
  },
  {
    "path": "LICENSE",
    "content": "Copyright (c) 2018\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the \"Software\"), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies\nof the Software, and to permit persons to whom the Software is furnished to do\nso, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "<p align=\"center\"><img width=\"280\" src=\"https://i.imgur.com/VwF0DyE.png\" alt=\"Task Easy Logo\"></p>\n\n<div align=\"center\">\n  <p><a href=\"https://www.npmjs.com/package/task-easy\"><img src=\"https://img.shields.io/npm/v/task-easy.svg?style=flat-square\" alt=\"npm\" /></a>\n  <a href=\"https://github.com/cmseaton42/task-easy/blob/master/LICENSE\"><img src=\"https://img.shields.io/github/license/cmseaton42/task-easy.svg?style=flat-square\" alt=\"license\" /></a>\n  <img src=\"https://img.shields.io/travis/cmseaton42/task-easy.svg?style=flat-square\" alt=\"Travis\" />\n  <img src=\"https://img.shields.io/coveralls/github/cmseaton42/task-easy.svg?style=flat-square\" alt=\"Coveralls github\" />\n  <a href=\"https://github.com/cmseaton42/task-easy\"><img src=\"https://img.shields.io/github/stars/cmseaton42/task-easy.svg?&amp;style=social&amp;logo=github&amp;label=Stars\" alt=\"GitHub stars\" /></a>\n</p>\n</div>\n\n# Task Easy - Promise Queue Made Easy ✅\n\nA simple, customizable, and lightweight priority queue for promise based tasks.\n\n> Now with types!!! Big thanks to [Emiliano Heyns](https://github.com/retorquere) :beers:\n>\n> -   See below example for typescript version\n\n## Getting Started\n\nInstall with npm\n\n```\nnpm install task-easy --save\n```\n\n## How it Works\n\n**TaskEasy** is built as an extension of a simple heap data structure. Tasks are queued by simply passing a task (function) to the `.schedule` method along with an array of arguments to be called as well as an object to describe the task's relative priority. The caller is returned a promise which will resolve once the scheduled task has ran. Priority determination is left up to the user via a function that accepts task priority object and returns a judgement.\n\n### Usage\n\nThe usage of **TaskEasy** is best given by example so that is the route we will take.\n\nIn this example, we will be passing priority objects to the scheduler that will be marked by the following signature.\n\n```js\n{\n    // An integer representing priority,\n    // the higher the number the higher the priority\n    priority: Number,\n\n    // A timestamp to illustrate when the task\n    // was scheduled, used as a 'tie-breaker' for\n    // tasks of the same priority\n    timestamp: Date\n}\n```\n\n> **NOTE**\n>\n> The priority object's signature that you want to queue your items with is 100% up to you. 😄\n\nNow, let's create a function that will receive our priority objects and output a priority judgment so that _TaskEasy_ knows how to handle queued tasks. Our function will be passed two arguments (the priority objects of two scheduled tasks) and return a judgement indicating which task is of _higher_ priority. If we return `true`, then we are communicating to _TaskEasy_ that the first task is higher priority than the second task or vice versa\n\n```js\n// This function is passed to the TaskEasy contructor and will be used internally to determine tasks order.\nconst prioritize = (obj1, obj2) => {\n    return obj1.priority === obj2.priority\n        ? obj1.timestamp.getTime() < obj2.timestamp.getTime() // Return true if task 1 is older than task 2\n        : obj1.priority > obj2.priority; // return true if task 1 is higher priority than task 2\n};\n```\n\nNow, we can initialize a new _TaskEasy_ instance.\n\n```js\nconst { TaskEasy } = require(\"task-easy\");\n\nconst max_tasks = 200; // How many tasks will we allow to be queued at a time (defaults to 100)\nconst queue = new TaskEasy(prioritize, max_tasks);\n```\n\nNow, lets build an async function to demo the scheduler.\n\n```js\nconst delay = ms => new Promise(resolve => setTimeout(resolve, ms));\n```\n\n> **NOTE**\n>\n> Scheduled tasks _MUST_ be functions that return _promises_. This works well with async functions or with ES2017 `ASYNC/AWAIT` functions.\n\nNow, that we have a task to schedule, let's schedule some tasks. The `.schedule` method takes three arguments, the task to call, an array of arguments, and a priority object that is associated with the scheduled task. It will return a promise that will resolve or reject once the task has been ran.\n\n```js\n// .schedule accepts the task signature,\n// an array or arguments, and a priority object\nconst task1 = queue\n    .schedule(delay, [100], { priority: 1, timestamp: new Date() })\n    .then(() => console.log(\"Task 1 ran...\"));\n\nconst task2 = queue\n    .schedule(delay, [100], { priority: 1, timestamp: new Date() })\n    .then(() => console.log(\"Task 2 ran...\"));\n\nconst task3 = queue\n    .schedule(delay, [100], { priority: 2, timestamp: new Date() })\n    .then(() => console.log(\"Task 3 ran...\"));\n\nconst task4 = queue\n    .schedule(delay, [100], { priority: 1, timestamp: new Date() })\n    .then(() => console.log(\"Task 4 ran...\"));\n\nconst task5 = queue\n    .schedule(delay, [100], { priority: 3, timestamp: new Date() })\n    .then(() => console.log(\"Task 5 ran...\"));\n\n// OUTPUT\n// Task 1 ran...\n// Task 5 ran...\n// Task 3 ran...\n// Task 2 ran...\n// Task 4 ran...\n```\n\n> **NOTE**\n>\n> In the above example, `task1` resolved first as it once put onto the queue first and was immediately called as it was the only task on the queue at that time.\n\n## Now with _Typescript_\n\n```typescript\nimport { TaskEasy } from \"task-easy\";\n\n// Define interface for priority\n//  objects to be used in the\n//  TaskEasy instance\ninterface IPriority {\n    priority: number;\n    timestamp: Date;\n}\n\n// Define delay function type\n// -> Must extend  Task<T>: (...args) => Promise<T>\ntype delayFn = (ms: number) => Promise<undefined>;\n\n// Define delay function of type 'delayFn' defined above\nconst delay: delayFn = ms => new Promise(resolve => setTimeout(resolve, ms));\n\n// Define priority function\n// -> Must extend (obj1: T, obj2: T) =>\nconst prioritize = (obj1: IPriority, obj2: IPriority) => {\n    return obj1.priority === obj2.priority\n        ? obj1.timestamp.getTime() < obj2.timestamp.getTime() // Return true if task 1 is older than task 2\n        : obj1.priority > obj2.priority; // return true if task 1 is higher priority than task 2\n};\n\n// Initialize new queue\nconst queue = new TaskEasy(prioritize); // equivalent of TaskEasy<IPriority>(prioritize) via type inference\n\n// .schedule accepts the task signature,\n// an array or arguments, and a priority object\n// -> with type inference\nconst task1 = queue\n    .schedule(delay, [100], { priority: 1, timestamp: new Date() })\n    .then(() => console.log(\"Task 1 ran...\"));\n\nconst task2 = queue\n    .schedule(delay, [100], { priority: 1, timestamp: new Date() })\n    .then(() => console.log(\"Task 2 ran...\"));\n\n// Definitely typed\nconst task3 = queue\n    .schedule<undefined, delayFn>(delay, [100], { priority: 2, timestamp: new Date() })\n    .then(() => console.log(\"Task 3 ran...\"));\n\nconst task4 = queue\n    .schedule<undefined, delayFn>(delay, [100], { priority: 1, timestamp: new Date() })\n    .then(() => console.log(\"Task 4 ran...\"));\n\nconst task5 = queue\n    .schedule<undefined, delayFn>(delay, [100], { priority: 3, timestamp: new Date() })\n    .then(() => console.log(\"Task 5 ran...\"));\n\n// OUTPUT\n// Task 1 ran...\n// Task 5 ran...\n// Task 3 ran...\n// Task 2 ran...\n// Task 4 ran...\n```\n\n## Built With\n\n-   [NodeJS](https://nodejs.org/en/) - The Engine\n-   [javascript - ES2017](https://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf) - The Language\n\n## Contributers\n\n-   **Canaan Seaton** - _Owner_ - [GitHub Profile](https://github.com/cmseaton42) - [Personal Website](http://www.canaanseaton.com/)\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENCE](https://github.com/cmseaton42/task-easy/blob/master/LICENSE) file for details\n"
  },
  {
    "path": "package.json",
    "content": "{\n    \"name\": \"task-easy\",\n    \"version\": \"1.0.1\",\n    \"description\": \"A simple, customizable, and lightweight priority queue for promise based tasks.\",\n    \"main\": \"./src/index.js\",\n    \"types\": \"./src/index.d.ts\",\n    \"scripts\": {\n        \"test\": \"npm run lint && jest && npm run test:coverage && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js\",\n        \"test:local\": \"npm run lint && jest && npm run test:coverage\",\n        \"test:watch\": \"jest --watch\",\n        \"test:coverage\": \"jest --coverage\",\n        \"test:detailed\": \"jest --verbose\",\n        \"test:update\": \"jest -u\",\n        \"lint\": \"./node_modules/.bin/eslint . --ext .js\",\n        \"lint:fix\": \"npm run lint -- --fix\"\n    },\n    \"keywords\": [\n        \"queue\",\n        \"task\",\n        \"worker\",\n        \"job\",\n        \"in-memory\",\n        \"priority\",\n        \"manager\",\n        \"utility\",\n        \"promise\",\n        \"Async\"\n    ],\n    \"repository\": {\n        \"type\": \"git\",\n        \"url\": \"https://github.com/cmseaton42/task-easy\"\n    },\n    \"author\": \"Canaan Seaton\",\n    \"license\": \"MIT\",\n    \"devDependencies\": {\n        \"coveralls\": \"^3.0.9\",\n        \"eslint\": \"^6.8.0\",\n        \"eslint-plugin-jest\": \"^23.4.0\",\n        \"jest\": \"^24.9.0\"\n    }\n}\n"
  },
  {
    "path": "src/__snapshots__/task-easy.spec.js.snap",
    "content": "// Jest Snapshot v1, https://goo.gl/fbAQLP\n\nexports[`Micro Worker Private Methods Reorder Method Produces Correct Output 1`] = `\nArray [\n  Object {\n    \"args\": Array [\n      200,\n    ],\n    \"priority_obj\": Object {\n      \"value\": 2,\n    },\n    \"task\": [Function],\n  },\n  Object {\n    \"args\": Array [\n      100,\n    ],\n    \"priority_obj\": Object {\n      \"value\": 1,\n    },\n    \"task\": [Function],\n  },\n  Object {\n    \"args\": Array [\n      600,\n    ],\n    \"priority_obj\": Object {\n      \"value\": 6,\n    },\n    \"task\": [Function],\n  },\n  Object {\n    \"args\": Array [\n      300,\n    ],\n    \"priority_obj\": Object {\n      \"value\": 3,\n    },\n    \"task\": [Function],\n  },\n  Object {\n    \"args\": Array [\n      400,\n    ],\n    \"priority_obj\": Object {\n      \"value\": 4,\n    },\n    \"task\": [Function],\n  },\n  Object {\n    \"args\": Array [\n      500,\n    ],\n    \"priority_obj\": Object {\n      \"value\": 5,\n    },\n    \"task\": [Function],\n  },\n  Object {\n    \"args\": Array [\n      1400,\n    ],\n    \"priority_obj\": Object {\n      \"value\": 14,\n    },\n    \"task\": [Function],\n  },\n  Object {\n    \"args\": Array [\n      700,\n    ],\n    \"priority_obj\": Object {\n      \"value\": 7,\n    },\n    \"task\": [Function],\n  },\n  Object {\n    \"args\": Array [\n      800,\n    ],\n    \"priority_obj\": Object {\n      \"value\": 8,\n    },\n    \"task\": [Function],\n  },\n  Object {\n    \"args\": Array [\n      900,\n    ],\n    \"priority_obj\": Object {\n      \"value\": 9,\n    },\n    \"task\": [Function],\n  },\n  Object {\n    \"args\": Array [\n      1000,\n    ],\n    \"priority_obj\": Object {\n      \"value\": 10,\n    },\n    \"task\": [Function],\n  },\n  Object {\n    \"args\": Array [\n      1100,\n    ],\n    \"priority_obj\": Object {\n      \"value\": 11,\n    },\n    \"task\": [Function],\n  },\n  Object {\n    \"args\": Array [\n      1200,\n    ],\n    \"priority_obj\": Object {\n      \"value\": 12,\n    },\n    \"task\": [Function],\n  },\n  Object {\n    \"args\": Array [\n      1300,\n    ],\n    \"priority_obj\": Object {\n      \"value\": 13,\n    },\n    \"task\": [Function],\n  },\n  Object {\n    \"args\": Array [\n      0,\n    ],\n    \"priority_obj\": Object {\n      \"value\": 0,\n    },\n    \"task\": [Function],\n  },\n]\n`;\n"
  },
  {
    "path": "src/index.d.ts",
    "content": "// Task Easy Class\nexport declare class TaskEasy<C> {\n    constructor(compare_func: (ob1: C, obj2: C) => boolean, max_queue_size?: number);\n    schedule<P, T extends TaskEasy.Task<P>>(task: T, args: TaskEasy.Arguments<T>, priority_obj: C): Promise<P>;\n}\n\ndeclare namespace TaskEasy {\n    // Extract argument types from passed function type\n    export type Arguments<T> = [T] extends [(...args: infer U) => any] ? U : [T] extends [void] ? [] : [T];\n\n    // Generic task type, must return promise\n    export type Task<T> = (...args: any[]) => Promise<T>;\n}\n"
  },
  {
    "path": "src/index.js",
    "content": "/**\n * A simple in memory priority queue\n *\n * @class TaskEasy\n * @param {Function} compare_func - Function to handle comparison objects passed to Scheduler\n * @param {Number} [max_queue_size=100] Max number of tasks allowed in queue\n */\nclass TaskEasy {\n    constructor(compare_func, max_queue_size = 100) {\n        this.tasks = [];\n        this.taskRunning = false;\n\n        if (typeof compare_func !== \"function\")\n            throw new Error(\n                `Task Easy Comparison Function must be of Type <function> instead got ${typeof compare_func}`\n            );\n\n        if (typeof max_queue_size !== \"number\")\n            throw new Error(`Task Easy Max Queue Size must be of Type <Number> instead got ${typeof max_queue_size}`);\n\n        if (max_queue_size <= 0) throw new Error(\"Task Easy Max Queue Size must be greater than 0\");\n\n        this.compare = compare_func;\n        this.max = max_queue_size;\n    }\n\n    /**\n     * Schedules a new \"Task\" to be Performed\n     *\n     * @param {function} task - task to schedule\n     * @param {Array} args - array of arguments to pass to task\n     * @param {object} priority_obj - object that will be passed to comparison handler provided in the constructor\n     * @returns\n     * @memberof TaskQueue\n     */\n    schedule(task, args, priority_obj) {\n        if (typeof task !== \"function\")\n            throw new Error(`Scheduler Task must be of Type <function> instead got ${typeof task}`);\n        if (!Array.isArray(args)) throw new Error(`Scheduler args must be of Type <Array> instead got ${typeof args}`);\n        if (typeof priority_obj !== \"object\")\n            throw new Error(`Scheduler Task must be of Type <Object> instead got ${typeof priority_obj}`);\n        if (this.tasks.length >= this.max) throw new Error(`Micro Queue is already full at size of ${this.max}!!!`);\n\n        // return Promise to Caller\n        return new Promise((resolve, reject) => {\n            // Push Task to Queue\n            if (this.tasks.length === 0) {\n                this.tasks.unshift({ task, args, priority_obj, resolve, reject });\n                this._reorder(0);\n                this._next();\n            } else {\n                this.tasks.unshift({ task, args, priority_obj, resolve, reject });\n                this._reorder(0);\n            }\n        });\n    }\n\n    /**\n     * Swaps the tasks with the specified indexes\n     *\n     * @param {number} ix\n     * @param {number} iy\n     * @memberof TaskEasy\n     */\n    _swap(ix, iy) {\n        const temp = this.tasks[ix];\n        this.tasks[ix] = this.tasks[iy];\n        this.tasks[iy] = temp;\n    }\n\n    /**\n     * Recursively Reorders from Seed Index Based on Outcome of Comparison Function\n     *\n     * @param {number} index\n     * @memberof TaskQueue\n     */\n    _reorder(index) {\n        const { compare } = this;\n        const size = this.tasks.length;\n\n        const l = index * 2 + 1;\n        const r = index * 2 + 2;\n\n        let swap = index;\n\n        if (l < size && compare(this.tasks[l].priority_obj, this.tasks[swap].priority_obj)) swap = l;\n        if (r < size && compare(this.tasks[r].priority_obj, this.tasks[swap].priority_obj)) swap = r;\n\n        if (swap !== index) {\n            this._swap(swap, index);\n            this._reorder(swap);\n        }\n    }\n\n    /**\n     * Executes Highest Priority Task\n     *\n     * @memberof TaskQueue\n     */\n    _runTask() {\n        this._swap(0, this.tasks.length - 1);\n\n        const job = this.tasks.pop();\n        const { task, args, resolve, reject } = job;\n\n        this._reorder(0);\n\n        this.taskRunning = true;\n\n        task(...args)\n            .then((...args) => {\n                resolve(...args);\n                this.taskRunning = false;\n                this._next();\n            })\n            .catch((...args) => {\n                reject(...args);\n                this.taskRunning = false;\n                this._next();\n            });\n    }\n\n    /**\n     * Executes Next Task in Queue if One Exists and One is Currently Running\n     *\n     * @memberof TaskQueue\n     */\n    _next() {\n        if (this.tasks.length !== 0 && this.taskRunning === false) {\n            this._runTask();\n        }\n    }\n}\n\nmodule.exports = { TaskEasy };\n"
  },
  {
    "path": "src/task-easy.spec.js",
    "content": "const { TaskEasy } = require(\"./index\");\n\nconst delay = ms => new Promise(resolve => setTimeout(resolve, ms));\n\ndescribe(\"Micro Worker\", () => {\n    describe(\"New Instance\", () => {\n        it(\"Rejects Improper Constructor Arguments\", () => {\n            const fn = (arg, max) => () => new TaskEasy(arg, max);\n\n            expect(fn()).toThrow();\n            expect(fn(\"hello\", 6)).toThrow();\n            expect(fn({ a: 6 }, 6)).toThrow();\n            expect(fn(() => console.log(\"hello\"), 0)).toThrow();\n            expect(fn(() => console.log(\"hello\"), \"string\")).toThrow();\n            expect(fn(() => console.log(\"hello\"), 6)).not.toThrow();\n        });\n    });\n\n    describe(\"Private Methods\", () => {\n        let compare;\n        let arr;\n        let q;\n\n        beforeEach(() => {\n            arr = [];\n            compare = (obj1, obj2) => {\n                if (obj1.value === obj2.value) return obj1.id < obj2.id;\n                return obj1.value >= obj2.value;\n            };\n\n            for (let i = 0; i < 15; i++) {\n                arr.push({\n                    task: delay,\n                    args: [100 * i],\n                    priority_obj: { value: i }\n                });\n            }\n\n            q = new TaskEasy(compare);\n            q.tasks = arr;\n        });\n\n        it(\"Reorder Method Produces Correct Output\", () => {\n            q._reorder(0);\n            expect(q.tasks).toMatchSnapshot();\n        });\n\n        it(\"Runs Tasks on Push\", async () => {\n            const delayReturn = ms =>\n                new Promise((resolve, reject) => {\n                    if (typeof ms !== \"number\") reject(\"Bad Input\");\n                    else\n                        setTimeout(() => {\n                            resolve(ms);\n                        }, ms);\n                });\n\n            const q = new TaskEasy(compare);\n            const p1 = q.schedule(delayReturn, [50], { value: 1 });\n            const p2 = q.schedule(delayReturn, [60], { value: 1 });\n            const p3 = q.schedule(delayReturn, [70], { value: 1 });\n\n            await expect(p1).resolves.toBe(50);\n            await expect(p2).resolves.toBe(60);\n            await expect(p3).resolves.toBe(70);\n        });\n\n        it(\"Runs Tasks on Priority\", async () => {\n            const delayReturn = ms =>\n                new Promise((resolve, reject) => {\n                    if (typeof ms !== \"number\") reject(\"Bad Input\");\n                    else\n                        setTimeout(() => {\n                            resolve(ms);\n                        }, ms);\n                });\n\n            const q = new TaskEasy(compare);\n            const res = [];\n            const p1 = q.schedule(delayReturn, [100], { value: 1, id: 1 }).then(n => res.push(n));\n            const p2 = q.schedule(delayReturn, [110], { value: 1, id: 2 }).then(n => res.push(n));\n            const p3 = q.schedule(delayReturn, [120], { value: 2, id: 3 }).then(n => res.push(n));\n            const p4 = q.schedule(delayReturn, [130], { value: 3, id: 4 }).then(n => res.push(n));\n            const p5 = q.schedule(delayReturn, [140], { value: 1, id: 5 }).then(n => res.push(n));\n            const p6 = q\n                .schedule(delayReturn, [\"hello\"], { value: 0, id: 6 })\n                .then(n => res.push(n))\n                .catch(e => res.push(e));\n            const p7 = q.schedule(delayReturn, [90], { value: 4, id: 5 }).then(n => res.push(n));\n            const p8 = q.schedule(delayReturn, [70], { value: 2, id: 6 }).then(n => res.push(n));\n            const p9 = q.schedule(delayReturn, [105], { value: 1, id: 7 }).then(n => res.push(n));\n            const p10 = q\n                .schedule(delayReturn, [107], {\n                    value: 2,\n                    id: 8\n                })\n                .then(n => res.push(n));\n            const p11 = q\n                .schedule(delayReturn, [80], {\n                    value: 5,\n                    id: 9\n                })\n                .then(n => res.push(n));\n\n            await Promise.all([p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11]);\n\n            expect(res).toEqual([100, 80, 90, 130, 120, 70, 107, 110, 140, 105, \"Bad Input\"]);\n        });\n    });\n\n    describe(\"Public Methods\", () => {\n        let compare;\n\n        beforeEach(() => {\n            compare = (obj1, obj2) => {\n                if (obj1.value === obj2.value) return obj1.id < obj2.id;\n                return obj1.value >= obj2.value;\n            };\n        });\n\n        describe(\"Scheduler\", () => {\n            it(\"It Rejects Bad Args\", () => {\n                const q = new TaskEasy(compare);\n                const fn = (func, args, obj) => () => {\n                    q.schedule(func, args, obj);\n                };\n\n                expect(fn(12, [12, 12], { test: 12 })).toThrow();\n                expect(fn(\"12\", [12, 12], { test: 12 })).toThrow();\n                expect(fn(arg => console.log(arg), \"hello\", { test: 12 })).toThrow();\n                expect(fn(arg => console.log(arg), [\"hello\"], \"test\")).toThrow();\n                expect(fn(arg => console.log(arg), [\"hello\"], { test: 12 })).not.toThrow();\n            });\n\n            it(\"Throws if too many tasks queued\", () => {\n                const q = new TaskEasy(compare, 10);\n\n                const fn = () => {\n                    for (let i = 0; i < 15; i++) {\n                        q.schedule(delay, [i * 10], { value: i, id: i });\n                    }\n                };\n\n                expect(fn).toThrow();\n            });\n        });\n    });\n});\n"
  }
]