npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

minimq

v1.1.6

Published

A tiny message queue module for JS async operations.

Downloads

5

Readme

MiniMQ

A tiny message queue module for JS async operations.

Installation

MiniMQ is usable both in the browser and Node.js, and can be installed in npm by using the following command: npm install minimq

Usage

Put the require statement somewhere in your code. const MiniMQ = require("minimq");
An instance of MiniMQ is created by calling MiniMQ with the new keyword. let queue = new MiniMQ();

In a MiniMQ instance, you can push elements at any time, however, the queue at any time may be closed or open. If the queue instance is open, then the element will be passed to the handler function, and if the queue is closed, it will be backed up internally until the queue is opened again. When the queue is opened, the elements will be passed to the handler in the order in which they entered the queue.

The handler function should be set when an instance of MiniMQ is created. This function will handle all the elements that pass through the queue.

Methods

addElement(el)

Adds an element el to the queue. If the queue is open, the element will be immediately handled by the handler function. If not, it will be stored internally until the queue is open again. Returns a Promise that can e resolved or rejected by the handler function when the element is processed.

openQueue()

Opens the queue, allowing all subsequently inserted elements to be processed immediately by the handler function. If there are any elements stored internally in the queue, they will be passed to the handler function in the order in which they were inserted.

closeQueue()

Closes the queue, stopping all subsequent elements from being processed by the handler function. Instead, they will be stored internally in the queue until a later call of openQueue(). Note that all instances of MiniMQ start as closed by default, and must be opened explicitly before any processing can occur.

handlerFunction(el,prm,resolve,reject)

The handler function can be assigned to a user-defined function that handles the elements that come through the queue.

Params:

  • el - the element that passes through the queue
  • prm - the Promise that was created by the addElement function. It is included here if you want to chain it once it resolves or rejects.
  • resolve - a function that when called, resolves the above Promise. It can also take a value parameter that will be passed to whoever called addElement.
  • reject - a function that when called, rejects the above Promise. It can also take a value parameter that will be passed to whoever called addElement.

Example

let queue = new MiniMQ();	//by default the MiniMQ instance starts closed
queue.handlerFunction = (el,prm,resolve,reject) => {
	console.log(el);
	resolve();	
};
queue.addElement("foo");	//nothing happens at this point
queue.addElement("bar");	//nothing here either
queue.openQueue();			//at this point, "foo" and "bar" are printed in the console, and the Promises that were returned by addElement are resolved
queue.addElement("baz");	//"baz" is immediately printed to the console, and the Promise immediately resolved

Why I made this

I needed to send messages through a long-lived WebSocket connection, however, the connection would occasionally go down for a few seconds until it reconnected again. In this case, it was better that the client of the WebSocket object did not handle the logic to check if the connection was down or not. The client simply pushed the messages though WebSocket, and if the connection was down, the WebSocket library would hold on to the messages until the connection would be restored.

Final words

Made by Ermir Suldashi
License: MIT