1.2.1 • Published 9 months ago

aggregate-async-iterator v1.2.1

Weekly downloads
748
License
BSD-2-Clause
Repository
github
Last release
9 months ago

npm License Typed with TypeScript bundlejs downloads GitHub Issues Build Status Styled with prettier Commitizen friendly Known Vulnerabilities Coverage Status

aggregate-async-iterator

Aggregates several async iterators into one (zip)

usage

import { aggregateRoundRobin, aggregateFifo } from "aggregate-async-iterator";

async function* sequence(name, time = 100, num = 10) {
  for (let i = 0; i < num; i += 1) {
    yield new Promise(resolve => setTimeout(resolve(name + i), time));
  }
}

console.log("RR:");

for await (const r of aggregateRoundRobin([
    sequence("A", 100, 3),
    sequence("B", 35, 5)
  ])) {
  console.log(r);
}

console.log("FIFO:");

for await (const r of aggregateFifo([
    sequence("A", 100, 3),
    sequence("B", 35, 5)
  ])) {
  console.log(r);
}

Prints interleaved sequences

RR:
A0
B0
A1
B1
A2
B2
B3
B4
FIFO:
A0
B0
A1
B1
A2
B2
B3
B4

API

Table of Contents

aggregateFifo

Aggregate items from sevaral async iterators into one. Items are collected first in first out from the sources. Whatever source comes first will be delivered first.

Parameters

  • sources Array\<AsyncIterator\>

Returns AsyncIterable\ items collected from all sources

aggregateRoundRobin

Aggregate items from sevaral async iterators into one. Items are collected round robin from the sources. The 2nd. round of items will only be delivered after all sources have delivered their 1st. round (or reached their end).

Parameters

  • sources Array\<AsyncIterator\>

Returns AsyncIterable\ items collected from all sources

install

With npm do:

npm install aggregate-async-iterator

license

BSD-2-Clause

1.2.1

9 months ago

1.2.0

9 months ago

1.1.16

2 years ago

1.1.12

2 years ago

1.1.11

2 years ago

1.1.10

3 years ago

1.1.15

2 years ago

1.1.14

2 years ago

1.1.13

2 years ago

1.1.9

3 years ago

1.1.8

3 years ago

1.1.7

3 years ago

1.1.6

3 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago