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

buffered-async-iterator

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

buffered-async-iterator

`buffer` wraps an async iterator into another async iterator, buffering items from the wrapped async iterator. This buffering allows the inner iterator to produce items concurrently with consumption of the items from the outer iterator. An example will

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
increased by200%
Maintainers
1
Weekly downloads
 
Created
Source

buffered-async-iterator

buffer wraps an async iterator into another async iterator, buffering items from the wrapped async iterator. This buffering allows the inner iterator to produce items concurrently with consumption of the items from the outer iterator. An example will help:

const buffer = require('buffered-async-iterator');

const someSlowIterator = ..;

for await (let item of buffer(someSlowIterator, 20)) {
  await someSlowOperation(item);
}

Here, someSlowIterator can slowly produce items (perhaps it is querying them from a database) and we can perform someSlowOperation on those items (perhaps calling some HTTP API). Both the DB queries and the HTTP calls will happen concurrently.

Without this functionality (that is, with for await (let item of someSlowIterator)), the DB queries and the HTTP calls would alternate, each unnecessarily waiting for the other.

The buffer has a length property which gives the current number of buffered items.

const buf = buffer(someSlowIterator, 20);
for await (let item of buffer) {
  await someSlowOperation(item);
  console.log(`${buf.length} items currently buffered`);
}

Inspiration

Inspired by https://github.com/mirkokiefer/async-iterators but updated for modern async iterators

FAQs

Package last updated on 09 Apr 2020

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