jkuester:reactive-queue

v1.0.0Published 2 years ago

Meteor reactive queue

built with Meteor Project Status: Active – The project has reached a stable, usable state and is being actively developed. JavaScript Style Guide GitHub

This is a simple and lightweight package (< 100 lines) that provides a reactive queue implementation to work with Meteor's Tracker.

Installation

$ meteor add jkuester:reactive-queue

Usage

1import { ReactiveQueue } from 'meteor/jkuester:reactive-queue'
2
3const queue = new ReactiveQueue()
4
5// this will automatically run when a new value
6// is added to the queue
7Tracker.autorun(() => {
8  const num = queue.dequeue()
9  console.debug(num)
10})
11
12// fast enqueue some numbers
13Meteor.setInterval(() => queue.add(Math.random()), 25)

How it works

The queue registers any dependency changes when enqueue is called, which allows to peek (check the first element but not remove it) or dequeue reactively, once new data flows in.

License

MIT, see LICENSE file