JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 775
  • Score
    100M100P100Q97273F
  • License MIT

Safely execute asynchronous functions

Package Exports

  • fuuu

Readme

fuuu

A TypeScript utility function to safely execute asynchronous functions.

Installation

You can install this package using npm:

npm install fuuu

Usage

import * as f from "fuuu"

interface People {
  name: string
  height: string
  mass: string
  gender: string
}

const getVaderDetails = async () => {
  const response = await fetch("https://swapi.dev/api/people/4/")
  return response.json() as Promise<People>
}

const main = async () => {
  const vader = await f.safe(getVaderDetails)

  if (vader.error) {
    // error handling
    return
  }

  console.log(vader.data)
}

Retries

const vader = await f.safe(getVaderDetails, {
  retries: 3,
  retryDelay: 1000,
})

Timeout

const vader = await f.safe(getVaderDetails, {
  timeout: 3000,
})

const isTimeoutError = vader.error instanceof f.TimeoutError