localstorage-fifo-queue

This package contains a persistant FIFO queue implementation working with localstorage. It can enqueue and dequeue items, as well as peek the next item without deleting it.

Usage no npm install needed!

<script type="module">
  import localstorageFifoQueue from 'https://cdn.skypack.dev/localstorage-fifo-queue';
</script>

README

Storage queue

This package contains a persistant FIFO queue implementation working with localstorage. It can enqueue and dequeue items, as well as peek the next item without deleting it.

Usage

import { LocalStorageQueue } from './src/local-storage-queue';

interface Message {
    hello: string;
    world: number;
}

const queue = new LocalStorageQueue<Message>('myQueue');
queue.initialize();

queue.enqueue({
    hello: '123',
    world: 123
});

queue.enqueue({
    hello: '456',
    world: 456
});

queue.peek(); 		
// { hello: '123', world: 123 } item still in the queue

queue.dequeue(); 	
// { hello: '123', world: 123 } item deleted from queue

queue.dequeue(); 	
// { hello: '456', world: 456 } item deleted from queue

queue.dequeue(); 	
// null	 queue is empty