Skip to content

Queue

Module Collections.Queues

A queue has the logic of waiting in line at the bakery. First in, first out.

Queues.immutable creates a queue, returning type Interface IQueueImmutable .

import { Queues } from "https://unpkg.com/@ixfx/collections/bundle"
let q = Queues.immutable();
q = q.enqueue(`a`, `b`); // Add two strings
const front = q.peek; // `a`, since it's the front of the queue (oldest)
q = q.dequeue(); // q now just consists of `b`
Queues.QueueMutable
import { Queues } from "https://unpkg.com/@ixfx/collections/bundle"
const q = new Queues.QueueMutable();
q.enqueue(`a`, `b`); // Add two strings
const item = q.dequeue(); // Remove & return `a` from front of queue
q.peek; // `b`

QueueMutable class also has events to monitor changes to the data.

// Sub module
import { Queue } from "@ixfx/collections.js"
// Eg: Queue.immutable();
// Whole module
import * as Collections from "@ixfx/collections.js"
// Eg: Collections.Queue.immutable();
// From bundle
import { Collections } from "@ixfx"
// Eg: Collections.Queue.immutable();
// And within your HTML's <HEAD> </HEAD> block:
<script type="importmap">{ "imports": { "@ixfx":"/ixfx/index.js", "@ixfx/": "/ixfx/" } }</script>