An open API service indexing awesome lists of open source software.

https://github.com/richienb/cache-async-iterator

Cache future values in an async iterator by calling .next() early
https://github.com/richienb/cache-async-iterator

async iterator

Last synced: 10 months ago
JSON representation

Cache future values in an async iterator by calling .next() early

Awesome Lists containing this project

README

          

# cache-async-iterator

> Cache future values in an async iterator by calling `.next()` early

## Install

```sh
npm install cache-async-iterator
```

## Usage

```js
import cacheAsyncIterator from 'cache-async-iterator';

for await (const value of cacheAsyncIterator(asyncIterator, 2)) {
// The 2 values after the current value are already being collected while the code here runs.
}
```

## API

### cacheAsyncIterator(asyncIterator, cacheSize)

#### asyncIterator

Type: `AsyncIterator`

The async iterator to cache.

#### cacheSize

Type: `number`

The amount of future values to cache.