Skip to content

rbnts/race

Repository files navigation

@rbnlffl/race

latest version npm downloads typescript types license

Whoever resolves first, wins! 🏃‍♂️

Teeny-tiny wrapper around Promise.race that adds a timeout.

Installation

npm i @rbnlffl/race

Usage

import race from "@rbnlffl/race";

// race a single promise against a timeout
const result = await race(someAsyncOperation(), 5000);

// race multiple promises: resolves with whichever settles first
const first = await race([fetchFromPrimary(), fetchFromFallback()], 5000);

If the timeout expires before any promise settles, race rejects with an Error:

Error: Not settled after 5000ms!

License

MIT

About

Whoever resolves first, wins! 🏃‍♂️

Resources

Stars

Watchers

Forks

Contributors