
Security News
Feross on the 10 Minutes or Less Podcast: Nobody Reads the Code
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.
smart-queue
Advanced tools
A generic purpose *"delayed"* FIFO queue with ticket system, inspired by real life.
A generic purpose "delayed" FIFO queue with ticket system, inspired by real life.
hows and whysMost queue modules, at least those that I've been able to find, assume that you have already ordered your data and are ready to push it into a storage, which is not always the case, especially when asynchronous functions come into play.
The idea of a ticket system seems way easier to manage in many use cases. All
you have to do is request a ticket and store the data using the ticket whenever it
arrives (from other asynchronous sources), you don't have to worry about ordering
your data beforehand. The queue and tickets do it for you.
smart-queue is installable via:
var Queue = require('smart-queue'),
bouncer = function (err, status) {
console.log('The bouncer says: ' + (err || 'The queue has emptied'));
},
//We set a handler to be able to read errors and the queue status
q = new Queue({handler: bouncer}),
ticket,
timedTicket;
//Assume this is the queue of a club
//A permanent ticket is sold.
ticket = q.getTicket();
//A temporary ticket is sold. It must be used within a second or it expires.
timedTicket = q.getTicket(1000);
//Jimmy arrives at the club.
q.join('Jimmmy');
//Bob arrives at the club with the ticket that was sold earlier.
q.join(ticket, 'Bob');
//After a minute the queue process starts.
setTimeout(function () {
console.log(q.next());
=> {"1": "Bob"}
//As the queue is processing Megan tries to join with her ticket.
q.join(timedTicket, 'Megan', function () {
=> "The bouncer says: Ticket No. 2 has expired."
//Megan can still join the queue, but now she has to wait in line.
q.join('Megan');
});
console.log(q.next());
=> {"3": "Jimmy"}
console.log(q.next());
=> {"4": "Megan"}
q.next();
=> "The bouncer says: The queue has emptied"
}, 60000);
//Even if `Jimmy` arrived at the club before anyone else, whoever reserved
//a ticket earlier had the possibility to get in before him.
Creates an instance of smart-queue.
Parameters
(error, queueStatus) as arguments.A simplified and easier to digest version of the actual queue.
It present the queue in an object with the ticket as key and the specified data as value of said ticket.
Creates a placeholder into the next available queue position and returns its ticket.
Parameters
(error, queueStatus) as arguments.Parameters
(error, queueStatus) as arguments.Returns the current client in the queue.
Parameters
(error, queueStatus) as arguments.The very first time it's ran it will start the queue processing. Sequential call of next will remove the current client from the queue and advance the queue.
Parameters
(error, queueStatus) as arguments.Resets all the queue's data, except for the options passed through the Queue constructor.
FAQs
A generic purpose *"delayed"* FIFO queue with ticket system, inspired by real life.
The npm package smart-queue receives a total of 11 weekly downloads. As such, smart-queue popularity was classified as not popular.
We found that smart-queue demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.

Research
/Security News
Campaign of 108 extensions harvests identities, steals sessions, and adds backdoors to browsers, all tied to the same C2 infrastructure.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.