0.1.1 • Published 3 years ago

@fluzko/async-array v0.1.1

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

async-array

tests

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

0.1.1

3 years ago

0.1.0

3 years ago