A simple package to provide a queue class
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
Join our Discord server for quick communication with the team and for support.
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.
Permissions | Conditions | Limitations |
---|---|---|
Commercial use Distribution Modification Patent use Private use |
Disclose source License and copyright notice Same license (file) |
Liability Trademark use Warranty |