/ts-timeout-promise

Await timeout promise wrapper.

Primary LanguageTypeScript

ts-timeout-promise

Await timeout promise wrapper.

Table of contents

  1. Getting Started

  2. Usage

  3. Features

Getting Started

npm i ts-timeout-promise

Usage

Simple

import { timeout } from 'ts-timeout-promise';

const bootstrap = async () => {
    console.log(`Hello`);
    await timeout(1000);
    console.log(`1 second passed.`);
};

Advanced

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