0.0.5 • Published 1 year ago

@gustawdaniel/async-queue v0.0.5

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

Node.js Package

Async Queue

Super simple below 100 lines queue implementation build with Promise.race and AsyncIterator.

Features:

  • you can quite it by stop loosing all unprocessed items that it useful in tests
  • you do not have to connect with redis or open any port, everything works in memory
  • define simple processing function and forget about it, now you can simply push items to process

Installation

npm i @gustawdaniel/queue-async

Usage

import {AsyncQueue, Queue} from '@gustawdaniel/queue-async';

let sum = 0
const queue: Queue<number> = new AsyncQueue<number>(async (item) => {
    sum += item
})
for (const i of new Array(6).fill(1)) {
    queue.push(i)
}
queue.start()
await sleep(1)
expect(sum).toEqual(6)

Interface

export interface Queue<T> {
    state: 'open' | 'closed'

    push(item: T): void

    pull(): Promise<T>

    start(): void

    stop(): void

    [Symbol.asyncIterator](): AsyncIterator<T>
}
0.0.5

1 year ago

0.0.4

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago