Monster.Types. Queue

A queue is a list of items that are processed one after another (first in, first out).

With a queue you can add items to the end of the list Queue.add() and remove items from the beginning of the list Queue.pop().

With Queue.peek() you can get the first item without removing it from the list.

You can create the instance via new Queue().

Constructor

new Queue()

A Queue (Fifo)

Since
  • 1.4.0
License
  • AGPLv3
Example
import {Queue} from '@schukai/monster/source/types/queue.mjs';

const queue = new Queue;

queue.add(2);
queue.add(true);
queue.add("Hello");
queue.add(4.5);

console.log(queue.poll());
// ↦ 2
console.log(queue.poll());
// ↦ true
console.log(queue.poll());
// ↦ "Hello"
console.log(queue.poll());
// ↦ 4.5
console.log(queue.poll());
// ↦ undefined

Members

(static) instanceSymbol

This method is called by the instanceof operator.

This method is called by the instanceof operator.

Since
  • 2.1.0

Methods

add(value) → {Queue}

Add a new element to the end of the queue.

Add a new element to the end of the queue.

Parameters:
NameTypeDescription
value*
Returns:
Type: 
Queue

clear() → {Queue}

remove all entries

.

remove all entries

Returns:
Type: 
Queue

isEmpty() → {boolean}

Returns:
Type: 
boolean

peek() → {*}

Read the element at the front of the queue without removing it.

Read the element at the front of the queue without removing it.

Returns:
Type: 
*

poll() → {*}

Remove the element at the front of the queue If the queue is empty, return undefined.

Remove the element at the front of the queue If the queue is empty, return undefined.

Returns:
Type: 
*