1.0.2 • Published 9 months ago

@jaypaulincodes/ssqueue v1.0.2

Weekly downloads
-
License
Mozilla Public Li...
Repository
github
Last release
9 months ago

ssQueue

A simple package to provide a queue class

Usage

Install using NPM

npm install @jaypaulincodes/ssqueue

Import the package with the following import statement:

import Queue from "@jaypaulincodes/ssqueue";

Once imported you can create a new queue:

const MY_QUEUE = new Queue();

You can use the enqueue() method to add items to the queue:

MY_QUEUE.enqueue("foo");

Using the dequeue() method you can retreive the next item in the queue, removing it from the queue in the process:

const nextItem = MY_QUEUE.dequeue();

Complete example code:

import Queue from "@jaypaulincodes/ssqueue";

const MY_QUEUE = new Queue();

MY_QUEUE.enqueue("dog");
MY_QUEUE.enqueue("cat");
MY_QUEUE.enqueue("frog");

console.log("Starting to process queue of not frogs");

while (MY_QUEUE.hasNext) {
    if (MY_QUEUE.peek() === "frog") {
        break;
    }

    console.log(`Processing queue item: ${MY_QUEUE.dequeue()}`);
}

console.log("Finished processing queue");

Output:

Starting to process queue of not frogs
Processing queue item: dog
Processing queue item: cat
Finished processing queue

Discord

Join our Discord server for quick communication with the team and for support.

License

This project uses the Mozilla Public License 2.0 Permissions of this weak copyleft license are conditioned on making available source code of licensed files and modifications of those files under the same license (or in certain cases, one of the GNU licenses). Copyright and license notices must be preserved. Contributors provide an express grant of patent rights. However, a larger work using the licensed work may be distributed under different terms and without source code for files added in the larger work. The license can be read here The following table provides a breif overview of the license. Hovering each point will provide a more detailed description.

PermissionsConditionsLimitations
Commercial use Distribution Modification Patent use Private use Disclose source License and copyright notice Same license (file) Liability Trademark use Warranty
1.0.2

9 months ago

1.0.1

9 months ago

1.0.0

9 months ago