Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/radarsu/ts-timeout-promise
Await timeout promise wrapper.
https://github.com/radarsu/ts-timeout-promise
await promise settimeout timeout typescript
Last synced: 2 days ago
JSON representation
Await timeout promise wrapper.
- Host: GitHub
- URL: https://github.com/radarsu/ts-timeout-promise
- Owner: radarsu
- Created: 2017-06-10T09:43:01.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-08-26T14:44:58.000Z (about 4 years ago)
- Last Synced: 2024-04-25T14:03:09.547Z (7 months ago)
- Topics: await, promise, settimeout, timeout, typescript
- Language: TypeScript
- Homepage:
- Size: 2.93 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
ts-timeout-promise
Await timeout promise wrapper.## Table of contents
1. [Getting Started](#getting-started)
2. [Usage](#usage)
3. [Features](#features)
## Getting Started
`npm i ts-timeout-promise`## Usage
### Simple```ts
import { timeout } from 'ts-timeout-promise';const bootstrap = async () => {
console.log(`Hello`);
await timeout(1000);
console.log(`1 second passed.`);
};
```### Advanced
```ts
import { timeout } from 'ts-timeout-promise';const bootstrap = async () => {
const promise = timeout(1000)
.then(() => {
console.log(`1 second has passed.`);
})
.catch(() => {
console.log(`Promise rejected.`);
});// Clears timeout.
promise.clear();// Clears timeout and rejects promise.
promise.reject();// Clears timeout and resolves promise.
promise.resolve();
};
```## Features
- **0 dependencies** - no dependencies
- **Simple** - just 40 lines of clean TypeScript code
- **Strongly typed** - returns TimeoutPromise with reject(), remains strongly typed