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

file-queue

v0.3.0

Published

A file system based queue (implemented using maildir)

Downloads

428

Readme

File-Queue

A simple file system based queuing implementation. Based on the maildir format, the queues are lockfree and therefore work in most situatuions. Look here for the maildir specification. The queue organises everything in FIFO (first-in first-out) order, because of that it is not possible to get the messages of the queue with random access. All objects are encoded using json and therefore can be easily read manually.

This queuing library has a specialty, its supports transactions for popping items.

Create a queue

The queue is created based on a folder. The passed folder will contain have three directories cur, tmp and new. The names of the files follow the maildir conventions.

var Queue = require('file-queue').Queue,
    queue = new Queue('.', callback);

Dealing with many files and common filesystem errors

If you deal with lots of files EMFILE errors (too many open files errors) can occur. Issacs wrote the graceful-fs package to deal with these errors. To use it simply pass the filesystem library that you prefer:

var queue = new Queue({
    path: 'tmp',
    fs: require('graceful-fs')
}, done);

Pushing and popping messages from the queue

Popping a message can be done at any time. If the queue doesn't contain an item at the moment it 'blocks' until it does. If there was an error, while removing the message err will contain an error message.

queue.pop(function(err, message) {
  if (err) throw err;
  console.log(message);
});

Pushing an item into the queue could cause an error if e.g. no disk space is left on the device.

queue.push('Hello World', function(err) {
  if (err) throw err;
});

Getting the length of the queue

The queue length can easily be determined with the following call:

queue.length(function(err, length) {
  console.log(length);
});

Transactional popping

A transactional pop means, that the element is taken from the queue, but will not be removed until commit is called. The rollback action makes the item again available for popping.

queue.tpop(function(err, message, commit, rollback) {
  if (Processor.process(message) === true) {
    commit(function(err) { if (err) throw err; });
  } else {
    rollback(function(err) { if (err) throw err; });
  }
});

There can be multiple layers of transactions. Since transactional pops (tpops) don't block the popping in general, there can be multiple inside of each other. The downside is that it can't be assured that the messages are processed in order.

Clearing

To remove all items from a queue, for example for testing purposes, use clear.

queue.clear(function(err) { if (err) throw err; });