Skip to content

Commit

Permalink
Add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
richardscarrott committed Jan 18, 2022
1 parent 1b2e7f3 commit 757af62
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Since this works with async iterators it requires node 10 or higher.
## API

- [`batch()`](#batch)
- [`batchWithTimeout()`](#batchwithtimeout)
- [`buffer()`](#buffer)
- [`collect()`](#collect)
- [`concat()`](#concat)
Expand Down Expand Up @@ -84,6 +85,27 @@ for await (const pokemons of batch(10, getPokemon())) {
}
```

### batchWithTimeout
```ts
function batchWithTimeout<T>(size: number, timeout: number, iterable: AsyncIterable<T>): AsyncGenerator<T[]>
function batchWithTimeout<T>(size: number, timeout: number, iterable: Iterable<T>): Generator<T[]>
```

Like [`batch`](#batch) but flushes early if the `timeout` is reached. The batches may be shorter than size if there are not enough items. Returns a sync iterator if the `iterable` is sync, otherwise an async iterator. Errors from the source `iterable` are immediately raised.

`size` can be between 1 and `Infinity`.
`timeout` can be between 0 and `Infinity`.

```ts
import { batchWithTimeout } from 'streaming-iterables'
import { getPokemon } from 'iterable-pokedex'
// batch 10 pokemon while we process them
for await (const pokemons of batchWithTimeout(10, 100, getPokemon())) {
console.log(pokemons) // Up to 10 pokemon at a time!
}
```

### buffer
```ts
function buffer<T>(size: number, iterable: AsyncIterable<T>): AsyncIterable<T>
Expand Down

0 comments on commit 757af62

Please sign in to comment.