@rbnlffl/race
v0.0.3
Published
Whoever resolves first, wins! ๐โโ๏ธ
Readme
@rbnlffl/race
Whoever resolves first, wins! ๐โโ๏ธ
Teeny-tiny wrapper around Promise.race that adds a timeout.
Installation
npm i @rbnlffl/raceUsage
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!