1.1.10 • Published 2 years ago

async-kv v1.1.10

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

async-kv

Resolves promises in key-value pairs maintaining type information.

Prerequisites

  • NodeJS 12 or later

Installation

npm i async-kv
yarn add async-kv

Usage

import { all } from "async-kv"

all

Assumes all values are functions that return promises and resolves them in parallel.

Since this is using Promise.all under the hood it follows the same behaviour.

This returned promise will resolve when all of the input's promises have resolved, or if the input iterable contains no promises. It rejects immediately upon any of the input promises rejecting or non-promises throwing an error, and will reject with this first rejection message / error.

Basic

const data = await all({
  news: getNews,
  music: getMusic,
  movies: getMovies,
  games: getGames,
})

With parameters

const data = await all({
  news: getNews,
  music: () => getMusic("optional", "parameters"),
  movies: getMovies,
  games: getGames,
})

The really important information here is that the return types of the functions are mapped back to the data object and Typescript can continue knowing they've all been resolved.

Contributing

Please do!

Credits

License

MIT License

1.1.10

2 years ago

1.1.9

2 years ago

1.1.7

2 years ago

1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago