A simple array
wrapper that allows you to interact with async
content and self manageable promise resolution by passing an async generator function.
const generator = (i) => i + 1; // this can be any async function, ie an API call
const asyncArray = AsyncArray(generator);
asyncArray[0]; // This will set a promise at index 0
await asyncArray[0]; // This will resolve the promise to 1
Since it should behave as much as possible like an array, the following methods are supported:
- map
- filter
- reduce
- forEach
- find
- findIndex
- length
take in count that this methods will return a new common array
, not an AsyncArray
.
- wipe: this will empty the async array, and will set the length to 0
- wipeIndex: this will empty the async array at the given index
- clone: this will return a new AsyncArray with the same generator function
Contributions are always welcome!