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

pending-queue

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pending-queue

pending-queue ensures a certain asynchronous method only run once, and queues listeners which are registered to it.

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4.2K
decreased by-42.79%
Maintainers
1
Weekly downloads
 
Created
Source

Build Status

pending-queue

pending-queue ensures a certain asynchronous method only run once, and queues listeners which are registered to it.

Install

$ npm install pending-queue --save

Usage

const Queue = require('pending-queue')

let counter = 0
const queue = new Queue({
  load: (a, b) => {
    return new Promise((resolve) => {
      counter ++
      setTimeout(() => {
        resolve(a + b)
      }, 100)
    })
  }
})

function run () {
  queue.add(1, 2).then((value) => {
    console.log(value, counter)
  })
}

run()
run()
run()

// 3, 1
// 3, 1
// 3, 1

// So the load function ran only once.

new Queue({load, stringify})

  • load function(...params) the method to get the value
  • stringify function(params)=JSON.stringify stringify the parameters as the key to queue all asynchronous requests.

add(...params)

  • params Arguments which will be passed into load

Returns Promise

License

MIT

Keywords

FAQs

Package last updated on 08 Mar 2017

Did you know?

Socket

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.

Install

Related posts

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