Skip to content

Repository files navigation

Queue

versionMaintenancemitdepsizeKnown VulnerabilitiesBuild Status

SlimIO - Simple Queue system. This package has been created for the SlimIO core and does not aim to be a popular Queue package (it answer our needs).

What is it ?

If you do not know what a queue is, please read the following wikipedia page.

Requirements

Getting Started

This package is available in the Node Package Repository and can be easily installed with npm or yarn.

$ npm i @slimio/queue
# or
$ yarn add @slimio/queue

Usage example

constQueue=require("@slimio/queue");constqueue=newQueue();queue.enqueue("foo","bar");console.log(queue.idLenght("foo"));// 1console.log(queue.dequeue("foo"));// "bar"

API

An id is described by the following type: string|number|symbol. All following API are methods of Queue class.

enqueue(id, value: any): void

Enqueue data in a given queue (identified by his id).

const{ deepStrictEqual }=require("assert");constq=newQueue();constsym=Symbol("foo");q.enqueue(sym,1);q.enqueue(sym,2);constqueueData=[...q.dequeueAll(sym)];deepStrictEqual(queueData,[1,2]);
dequeue(id): any

Dequeue the first data that was enqueued in the given queue id. A null value is returned when there is no data in the queue!

const{ strictEqual }=require("assert");constq=newQueue();q.enqueue(100,1);q.enqueue("foo","bar");strictEqual(q.dequeue(100),1);strictEqual(q.dequeue("foo"),"bar");strictEqual(q.dequeue("foo"),null);
dequeueAll(id): Iterator< any >

Dequeue all data that was enqueued in the given queue id. The returned value is a JavaScript iterator, no data will be lost if the iterator is stoped.

const{ deepStrictEqual }=require("assert");constq=newQueue();q.enqueue("test",1);q.enqueue("test",2);q.enqueue("test",3);constqueueData=[...q.dequeueAll(100)];deepStrictEqual(queueData,[1,2,3]);
has(id): boolean

Check if a given queue id exist!

const{ strictEqual }=require("assert");constq=newQueue();q.enqueue("foo",null);strictEqual(q.has("foo"),true);strictEqual(q.has("fo"),false);
ids(): string[]

Get all registered queue ids.

const{ deepStrictEqual }=require("assert");constq=newQueue();q.enqueue(100,1);q.enqueue("foo","bar");q.enqueue("test",20);constids=q.ids();deepStrictEqual(ids,[100,"foo","test"]);
idLength(id): number

Return the number of elements of a given queue id.

const{ strictEqual }=require("assert");constq=newQueue();q.enqueue("test",20);q.enqueue("test",21);q.enqueue("test",22);constlen=queue.idLength("test");strictEqual(len,3);

Dependencies

NameRefactoringSecurity RiskUsage
@slimio/isMinorLowType Checker

License

MIT

About

SlimIO - Queue Class designed for SlimIO Core

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages