Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/hazae41/future

Just like a Promise but you can manually resolve or reject it
https://github.com/hazae41/future

async await browser finally future javascript promise typescript unit-test

Last synced: 28 days ago
JSON representation

Just like a Promise but you can manually resolve or reject it

Awesome Lists containing this project

README

        



Just like a Promise but you can manually resolve or reject it

```bash
npm i @hazae41/future
```

[**Node Package 📦**](https://www.npmjs.com/package/@hazae41/future)

## Features

### Current features
- 100% TypeScript and ESM
- No external dependencies
- Unit-tested

## Usage

```typescript
import { Future } from "@hazae41/future"

const future = new Future()

const t1 = setTimeout(() => future.resolve(), 1000)
const t2 = setTimeout(() => future.reject(), 2000)

try {
await future.promise
} finally {
clearTimeout(t1)
clearTimeout(t2)
}
```