Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@jakubneubauer/limited-blocking-queue

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jakubneubauer/limited-blocking-queue

  • 1.0.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

limited-blocking-queue

Javascript implementation of queue with asynchronous push/pull and with limit of stored items. Operation pull returns a promise fulfilled whenever the item will be available (possibly immediately). The push operation returns a promise fulfilled when the push is possible to perform. If the queue is not full, it will be immediately (with Promise.resolve()), if the queue is full, it will be when enough items will be pulled.

npm install --save @jakubneubauer/limited-blocking-queue

Example of Usage

Demonstration of async pull

import {LimitedBlockingQueue} from '@jakubneubauer/limited-blocking-queue';

var queue = new LimitedBlockingQueue();

// waits for next push()
queue.pull().then((result) => console.debug(result));

setTimeout(() => {
  queue.push('hello world')
}, 1000);

Demonstration of async push

import {LimitedBlockingQueue} from '@jakubneubauer/limited-blocking-queue';

var queue = new LimitedBlockingQueue(); // default size is 1

(async function() {
    // first push is done immediately
    queue.push(1).then(() => console.debug("first push done"));
    // second push is postponed because the queue is full
    queue.push(2).then(() => console.debug("second push done"));
    // Pull will make room in the queue, after that the second push will be done
    await queue.pull().then((item) => console.debug("Pulled item " + item));
    // This pulled item will be logged after the second push
    await queue.pull().then((item) => console.debug("Pulled item " + item));
})();

output:

first push done
Pulled item 1
second push done
Pulled item 2

FAQs

Package last updated on 12 May 2022

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