Queue

Monster.Types. Queue

You can create the instance via the monster namespace new Monster.Types.Queue().

<script type="module">
import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.30.0/dist/monster.js';
new Monster.Types.Queue()
</script>

Alternatively, you can also integrate this function individually.

<script type="module">
import {Queue} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.30.0/dist/modules/types/queue.js';
new Queue()
</script>

Constructor

# new Queue()

A Queue (Fifo)

Since:
  • 1.4.0
Example
import {Queue} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.30.0/dist/modules/types/queue.js';

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

Methods

# add(value) → {Queue}

Add a new element to the end of the queue.

Parameters:
Name Type Description
value *
Returns:
Type
Queue

# clear() → {Queue}

remove all entries

Returns:
Type
Queue

# isEmpty() → {boolean}

Returns:
Type
boolean

# peek() → {*}

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.

Returns:
Type
*