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
- Host: GitHub
- URL: https://github.com/richienb/cache-async-iterator
- Owner: Richienb
- License: mit
- Created: 2022-10-22T12:13:05.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-11-11T08:07:13.000Z (about 3 years ago)
- Last Synced: 2025-02-19T00:46:57.155Z (11 months ago)
- Topics: async, iterator
- Language: JavaScript
- Homepage:
- Size: 6.84 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
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.