@xcore24/queue
v1.0.6
Published
TypeScript library implementing the Queue pattern
Downloads
3
Readme
Queue
queue
is TypeScript library implementing the Queue pattern.
Installation
To start using queue install the npm package:
npm install @xcore24/queue
Basic Usage
import { Queue } from '@xcore24/queue';
const DEFAULT_QUEUE_NAME = 'simple-test-queue'
const queue = new Queue(DEFAULT_QUEUE_NAME)
const message1: Message = {
id: 1,
name: 'name-1',
}
const message2: Message = {
id: 2,
name: 'name-2',
}
const message3: Message = {
id: 3,
name: 'name-3',
foo: 'foo'
}
const message4 = () => 'test'
const message5 = Buffer.from('test-buffer')
queue.push(message1).push(message2).push(message3).push(message4()).push(message5)
console.log(['MESSAGE_COUNT:BEFORE'], queue.messages.length)
console.log(['ALL_MESSAGE:BEFORE'], queue.messages)
const lastMessage = queue.next()
console.log(['LAST_MESSAGE'], lastMessage)
const messageByIndex = queue.next(1)
console.log(['MESSAGE_BY_INDEX'], messageByIndex)
console.log(['MESSAGE_COUNT:AFTER'], queue.messages.length)
console.log(['ALL_MESSAGE:AFTER'], queue.messages)