Skip to content

rbnts/race

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

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