Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vitalets/promised-map
A map of promises that can be resolved or rejected by key
https://github.com/vitalets/promised-map
promise promise-library
Last synced: 19 days ago
JSON representation
A map of promises that can be resolved or rejected by key
- Host: GitHub
- URL: https://github.com/vitalets/promised-map
- Owner: vitalets
- Created: 2019-10-20T11:49:58.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-06T02:13:15.000Z (almost 2 years ago)
- Last Synced: 2024-10-15T00:42:04.167Z (about 1 month ago)
- Topics: promise, promise-library
- Language: TypeScript
- Size: 395 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# promised-map
[![Actions Status](https://github.com/vitalets/promised-map/workflows/autotests/badge.svg)](https://github.com/vitalets/promised-map/actions)
[![npm](https://img.shields.io/npm/v/promised-map.svg)](https://www.npmjs.com/package/promised-map)
[![license](https://img.shields.io/npm/l/promised-map.svg)](https://www.npmjs.com/package/promised-map)A map of promises that can be resolved or rejected by key.
Once promise is resolved/rejected, related key/value pair is automatically removed from map.## Contents
- [Installation](#installation)
- [Usage](#usage)
- [License](#license)## Installation
```bash
npm install promised-map
```## Usage
```js
import { PromisedMap } from 'promised-map';const map = new PromisedMap();
// set key/value pair and retrieve related promise.
const promise = map.set('foo', 42);// resolve promise later by key
map.resolve('foo', 'bar');// reject promise by key
map.reject('foo', new Error('error'));// check if promise is still pending
map.has('foo');// resolve all promises and clear map
map.resolveAll('bar');// reject all promises and clear map
map.rejectAll(new Error('error'));// iterate all promises
map.forEach((value, key) => { /* ... */ });
```## License
MIT @ [Vitaliy Potapov](https://github.com/vitalets)