Skip to content

Fluzko/async-array

Repository files navigation

async-array

tests npm

A simple array wrapper that allows you to interact with async content and self manageable promise resolution by passing an async generator function.

Usage

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

Suported methods

Array methods

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.

Special methods

  • 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

Contributing

Contributions are always welcome!

License

MIT

About

Async array management

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published