New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

dumb-queue

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dumb-queue - npm Package Compare versions

Comparing version 1.1.0 to 2.0.0

2

package.json
{
"name": "dumb-queue",
"version": "1.1.0",
"version": "2.0.0",
"description": "A simple queue that handles async functions with a wait time.",

@@ -5,0 +5,0 @@ "main": "src/queue.js",

@@ -22,10 +22,10 @@ dumb-queue

// The callback must return a promise so`the queue know when the task has finished.
queue(() => someAsyncSlowAction1())
queue.add(() => someAsyncSlowAction1())
// ...
// Further in your code.
queue(() => someAsyncSlowAction2())
queue.add(() => someAsyncSlowAction2())
// ...
// You can, of course, use non-async functions with the help of `async` which will
// always return a promise.
queue(async () => someSyncSlowAction3())
queue.add(async () => someSyncSlowAction3())

@@ -32,0 +32,0 @@ // Wait until the queue is empty.

module.exports = waitTime => {
const queue = []
const obj = callback => {
// Add the new callback.
queue.push(async () => {
await callback()
await new Promise(resolve => setTimeout(resolve, waitTime))
// Unqueue and call the next callback.
if (queue.length >= 1) {
queue.shift()
if (queue.length) {
queue[0]()
return {
add(callback) {
// Add the new callback.
queue.push(async () => {
await callback()
await new Promise(resolve => setTimeout(resolve, waitTime))
// Unqueue and call the next callback.
if (queue.length >= 1) {
queue.shift()
if (queue.length) {
queue[0]()
}
}
})
// Run the current callback directly if it's the only element in the queue.
if (queue.length == 1) {
queue[0]()
}
})
// Run the current callback directly if it's the only element in the queue.
if (queue.length == 1) {
queue[0]()
},
wait() {
// Wait until the queue is empty.
return new Promise(resolve => {
const interval = setInterval(
() => {
if (queue.length == 0) {
clearInterval(interval)
resolve()
}
},
1
)
})
}
}
// Add a method to wait until the queue is empty.
obj.wait = () => {
return new Promise(resolve => {
const interval = setInterval(
() => {
if (queue.length == 0) {
clearInterval(interval)
resolve()
}
},
1
)
})
}
return obj
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc