buffered-kueue

1.3.0 • Public • Published

Buffered Kueue

Build Status codecov

Help you to buffer your tasks

Features

  • Having lifecycle hooks
  • Flushing specific amount of items when interval reached

Install

npm install --save buffered-kueue

yarn add buffered-kueue

Intro

Quick Start

Using class BufferedQueue.

const BufferedQueue = require('buffered-kueue')
let result = null
const queue = new BufferedQueue({onFlush: (items) => { result = items }, flushInterval: 1000, flushSize: 1})

queue.push(1) // after 1000ms result -> [1]
queue.push(2) // after 2000ms result -> [2]

API

class BufferedQueue

constructor(options) => bufferedQueue: BufferedQueue

The options beginning with the symbol * are required.

  • *options.maxSize: Max size of queue. Default: Infinity
    • number
  • *options.flushSize: Flush size of queue. Default: Infinity
    • number
  • *options.flushInterval: Flush interval(ms) of queue. Default: 1000
    • number
  • *options.onFlush: Flush handler. Default: noop
    • function: (flushItems, allItems) => any
  • options.willPush: Lifecycle events, called before pushing new item. Default: noop
    • function: (item, allItems) => any
  • options.didPush: Lifecycle events, called after pushing new item. Default: noop
    • function: (item, allItems) => any
  • options.willFlush: Lifecycle events, called before flushing. Default: noop
    • function: (flushItems, allItems) => any
  • options.didFlush: Lifecycle events, called after flushing. Default: noop
    • function: (flushItems, allItems) => any
  • options.willStart: Lifecycle events, called before start. Default: noop
    • function: () => any
  • options.didStart: Lifecycle events, called after start. Default: noop
    • function: () => any
  • options.willStop: Lifecycle events, called before stop. Default: noop
    • function: () => any
  • options.didStop: Lifecycle events, called after stop. Default: noop
    • function: () => any
  • options.autoStart: Should auto start when pushing item. You have to manage start manualy when setting this to false. Default: true
    • boolean

push(item)

  • item: Item which would be pushed into the queue.

Dependents (0)

Package Sidebar

Install

npm i buffered-kueue

Weekly Downloads

0

Version

1.3.0

License

ISC

Unpacked Size

100 kB

Total Files

7

Last publish

Collaborators

  • chux0519