
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.
timeout-queue
Advanced tools
Add items to the end of a queue. If the item is not pulled off the queue before time expires then the item will call it's callback function and be pulled off the queue immediately.
npm install timeout-queue
const timeoutQueue = require('timeout-queue');
const start = Date.now();
// items added to the queue set to persist for 500 ms before calling
// the expired function and removing the item from the queue
const queue = timeoutQueue(500, expired);
// add two items to the queue, both will expire in 500 ms
queue.push('Bob');
queue.push('Jan');
// output the queue length
console.log(queue.length); // 2
setTimeout(function() {
const value = queue.next();
console.log(time() + 'Got ' + value); // "at 200 ms: Got Bob"
}, 200);
function expired(value) {
console.log(time() + 'Expired ' + value); // "at 500 ms: Expired Jan"
}
function time() {
return 'at ' + (Date.now() - start) + ' ms: ';
}
Get an instance of a timeout queue. Values added to the queue will last for the number of milliseconds specified in the defaultTimeToLive parameter. If they are not pulled off the queue before the value expires then the timeoutCallback function will be called with the value that was added to (and expired from) the queue.
Parameters
-1.timeToLive expires.Returns object with the next, push, and length,
Example
const timeoutQueue = require('timeout-queue');
const queue = timeoutQueue(500, function(value) {
console.log('Expired ' + value);
});
Get the length of the queue.
Returns a number.
Example
const timeoutQueue = require('timeout-queue');
const queue = timeoutQueue(500);
queue.push('Bob');
console.log(queue.length); // 1
Get the next item off of the queue.
Returns the value of the item pulled off the queue.
Example
const timeoutQueue = require('timeout-queue');
const queue = timeoutQueue(500);
queue.push('Bob');
const value = queue.next();
console.log(value); // "Bob"
Add a value to a timeout queue.
Parameters
Returns the value passed in.
Example 1: Value Only
const timeoutQueue = require('timeout-queue');
const queue = timeoutQueue(500, function(value) {
console.log('Expired ' + value);
});
queue.push('Bob');
Example 2: Value Plus Custom Expiration
const timeoutQueue = require('timeout-queue');
const queue = timeoutQueue(500, function(value) {
console.log('Expired ' + value);
});
queue.push('Bob', 700);
Example 3: Value Plus Extra Callback
const timeoutQueue = require('timeout-queue');
const queue = timeoutQueue(500, function(value) {
console.log('Expired ' + value);
});
queue.push('Bob', removed);
function removed(value, expired) {
console.log('Value removed: ' + value + ', Expired: ' + expired);
}
Example 4: All Arguments
const timeoutQueue = require('timeout-queue');
const queue = timeoutQueue(500, function(value) {
console.log('Expired ' + value);
});
queue.push('Bob', 700, removed);
function removed(value, expired) {
console.log('Value removed: ' + value + ', Expired: ' + expired);
}
FAQs
Create a queue where values time out if not removed soon enough
The npm package timeout-queue receives a total of 1 weekly downloads. As such, timeout-queue popularity was classified as not popular.
We found that timeout-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.