async-kv
TypeScript icon, indicating that this package has built-in type declarations

1.1.10 • Public • Published

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

Package Sidebar

Install

npm i async-kv

Weekly Downloads

11

Version

1.1.10

License

MIT

Unpacked Size

17.8 kB

Total Files

16

Last publish

Collaborators

  • tonytamps
  • brendan-jefferis