Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/susisu/promise-utils
Promise utilities
https://github.com/susisu/promise-utils
Last synced: 2 days ago
JSON representation
Promise utilities
- Host: GitHub
- URL: https://github.com/susisu/promise-utils
- Owner: susisu
- License: mit
- Created: 2020-04-12T07:18:17.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-04-03T17:30:11.000Z (9 months ago)
- Last Synced: 2024-12-14T16:03:26.085Z (12 days ago)
- Language: TypeScript
- Size: 403 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# @susisu/promise-utils
[![CI](https://github.com/susisu/promise-utils/workflows/CI/badge.svg)](https://github.com/susisu/promise-utils/actions?query=workflow%3ACI)
Promise utilities
``` shell
# npm
npm i @susisu/promise-utils
# yarn
yarn add @susisu/promise-utils
# pnpm
pnpm add @susisu/promise-utils
```## Usage
### `triplet`
Creates a triplet of a promise and its resolve and reject functions.
``` typescript
import { triplet } from "@susisu/promise-utils";const [promise, resolve, reject] = triplet();
resolve(42);
promise.then(res => {
console.log(res); // -> 42
});
```### `attachActions`
Attaches cancellable actions to a promise.
``` typescript
import { triplet, attachActions } from "@susisu/promise-utils";const [promise, resolve, reject] = triplet();
const [cancel] = attachActions(
promise,
res => { console.log(res); },
err => { console.log(err); }
);cancel();
resolve(42); // no output
```## License
[MIT License](http://opensource.org/licenses/mit-license.php)
## Author
Susisu ([GitHub](https://github.com/susisu), [Twitter](https://twitter.com/susisu2413))