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

mergeiterator

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mergeiterator

merges async iterators

  • 1.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
705
decreased by-41.15%
Maintainers
1
Weekly downloads
 
Created
Source

mergeiterator

Merges async iterators.

NPM version Build Status Coverage Status

Using

This utility is for merging together async iterators.

merge(collection_of_iterables): Iterable

Pass it a collection of iterables and it'll return an async iterator, which will contain all values from those iterables. Those iterables and the collection of them can be arrays, calls to generators, or any other kind of iterable, synchronous or async, finite or infinite.

import merge from "mergeiterator"

async function DoIt() {
	const array = [1,2,3]
	function *generator() {
		let i = 6
		while (true) yield (i++)
	})
	async function *asyncGenerator() {
		yield await Promise.resolve(4)
		yield Promise.resolve(5)
	})
	for await (const v of merge([array, generator(), asyncGenerator()])) {
		console.log(v)
	}
}
// 1 6 2 7 4 3 8 5 9 10 11 ...

mergeIterator function guarantees, that if some value is yielded by some of iterables that mergeIterator is passed, then that value will be eventually yielded by mergeIterator. It also guarantees that the order of values within the same iterable is preserved.

If some iterable yields a promise, its value will be yielded, not a promise itself.

If some iterable throws an error, that error will be redirected to a caller and other iterables will be closed.

API

Table of Contents

merge

Merges async or sync iterables into async one.

Parameters
  • sequences AnyIterable<AnyIterable<(Promise<T> | T)>>

Returns AsyncIterator<T>

Keywords

FAQs

Package last updated on 15 May 2019

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