Resolve parallel promises in key-value pairs whilst maintaining type information

Overview

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

You might also like...

🧩 TypeScript utility type in order to ensure to return only properties (not methods) containing values in primitive types such as number or boolean (not Value Objects)

🧩 TypeScript utility type in order to ensure to return only properties (not methods) containing values in primitive types such as number or boolean (not Value Objects)

🧩 TypeScript Primitives type TypeScript utility type in order to ensure to return only properties (not methods) containing values in primitive types

Dec 7, 2022

Very tiny function that checks if an object/array/value is shaped like another, with TypeScript type refining.

@suchipi/has-shape Very tiny (~200B before minification/compression) function that checks if an object/array/value is shaped like another, with TypeSc

Aug 13, 2022

Keep the type of storage value unchanged and change array and object directly. Supports listening to the changes and setting expires.

proxy-web-storage A more convenient way to use storage through proxy. try it on codesandbox. Install npm i proxy-web-storage Features Base Keep the ty

Dec 25, 2022

Parallel/concurrent async work, optionally using multiple threads or processes

parallel-park Parallel/concurrent async work, optionally using multiple processes Usage parallel-park exports two functions: runJobs and inChildProces

Mar 1, 2022

Course material for a ~10 hours introductionary course for Julia. Topics: Introduction, Parallel Programming, Data Science

Development We use Franklin.jl to generate the lecture material. To do so, simply activate the environment, use Franklin and run the local server: act

Dec 15, 2022

Create parallel reality of your Substrate network.

Chopsticks Create parallel reality of your Substrate network. Install Make sure you have setup Rust environment (= 1.64). Clone repository with submo

Dec 15, 2022

A simple HTML page maintaining list of To Do tasks using webpack and served by a webpack dev server.

Task Organiser In this project, we build a simple HTML list of To Do tasks using webpack and served by a webpack dev server. Built With HTML CSS Javas

Jun 24, 2022

Github Actions and Workflows that make maintaining Magento2 projects and modules easier.

Magento 2 GitHub Actions Opinionated Github Actions and Workflows to make building, testing, and maintaining Magento 2 Modules easier. README if you a

Dec 21, 2022

Digital Identifier is a secure, decentralized, anonymous and tampered proof way of maintaining and verifying all essential identity-based documents to create a unique digital identity of a person.

Digital Identifier is a secure, decentralized, anonymous and tampered proof way of maintaining and verifying all essential identity-based documents to create a unique digital identity of a person.

Digital Identifier 🧐 To design and develop a secure, decentralized, anonymous and tampered proof way of maintaining and verifying all essential ident

Dec 17, 2022
Comments
  • feat: change the deployment to be automated

    feat: change the deployment to be automated

    • What kind of change does this PR introduce? (Bug fix, feature, docs update, ...) Automated versioning and publishing

    • What is the current behavior? (You can also link to an open issue here) Manual versioning and publishing

    • What is the new behavior (if this is a feature change)? Nothing relevant to the behaviour of the code.

    • Other information:

    opened by tonytamps 0
Releases(v1.1.10)
  • v1.1.10(Jan 5, 2022)

  • 1.1.7(Jan 5, 2022)

    What's Changed

    • feat: change the deployment to be automated by @tonytamps in https://github.com/tonytamps/async-kv/pull/1

    New Contributors

    • @tonytamps made their first contribution in https://github.com/tonytamps/async-kv/pull/1

    Full Changelog: https://github.com/tonytamps/async-kv/commits/1.1.7

    Source code(tar.gz)
    Source code(zip)
Owner
Tony Tamplin
Tony Tamplin
Combine type and value imports using Typescript 4.5 type modifier syntax

type-import-codemod Combines your type and value imports together into a single statement, using Typescript 4.5's type modifier syntax. Before: import

Ian VanSchooten 4 Sep 29, 2022
Bookmate - Watch changes in Chrome bookmarks, and use bookmarks as an append-only key-value store via an fs-like API.

?? Bookmate An append-only key-value store built on Chrome bookmarks, plus an asychronous stream of Bookmark changes. For NodeJS Actual production exa

Cris 6 Nov 8, 2022
Byteroo - Key-value storage for your Node.js applications

Byteroo Byteroo is a key-value storage for your Node.js applications. Usage: const Byteroo = require('byteroo'); const storage = new Byteroo({ name:

JMax 1 Jan 3, 2022
A common front-end/Service Worker-based Key/Value database based on CacheStorage

Cache-DB A common front-end/Service Worker-based Key/Value database based on CacheStorage > const db = new CacheDB('ChenYFanDB') < undefined > await d

CrazyCreativeDream 4 Sep 30, 2022
Persistent key/value data storage for your Browser and/or PWA, promisified, including file support and service worker support, all with IndexedDB. Perfectly suitable for your next (PWA) app.

BrowstorJS ?? ?? ?? Persistent key/value data storage for your Browser and/or PWA, promisified, including file support and service worker support, all

Nullix 8 Aug 5, 2022
A simple in-memory key-value cache for function execution, allowing both sync and async operations using the same methods

A simple in-memory key-value cache for function execution, allowing both sync and async operations using the same methods. It provides an invalidation mechanism based both on exact string and regex.

cadienvan 10 Dec 15, 2022
Tool to sign data with a Cardano-Secret-Key // verify data with a Cardano-Public-Key // generate CIP-8 & CIP-36 data

Tool to sign data with a Cardano-Secret-Key // verify data with a Cardano-Public-Key // generate CIP-8 & CIP-36 data

Martin Lang 11 Dec 21, 2022
Inside-out promise; lets you call resolve and reject from outside the Promise constructor function.

Inside-out promise; lets you call resolve and reject from outside the Promise constructor function.

Lily Scott 3 Feb 28, 2022
The node module that allows you to control your Ethereum revocation lists & resolve revocation keys.

Ethereum Revocation Registry Controller The controller module for interacting with EIP-5539-compatible Ethereum revocation lists. Motivation The EIP-5

spherity 4 Sep 27, 2022
A Node.js library to calculate Uniswap V3 ratios (prices) from token pairs.

UniV3Prices A Node.js library to calculate Uniswap V3 ratios (prices) and liquidity (reserves). Features This library will allow you to: Calculate pri

Thanos Polychronakis 121 Dec 29, 2022