Options
All
  • Public
  • Public/Protected
  • All
Menu

Async helpers

Examples:

  • await timeout(1000) => Wait for 1 second
  • const busy = await isPending(promise) => Check if promise is pending
  • const [error, data] = await to(promise) => Unwrap promise

Index

Functions

Functions

isPending

  • isPending<T>(promise: T): Promise<boolean>
  • Type parameters

    • T

    Parameters

    • promise: T

    Returns Promise<boolean>

timeout

  • timeout(ms: number): Promise<void>

to

  • to<T>(promise: PromiseLike<T> | T): Promise<[undefined, T] | [Error, undefined]>
  • summary

    Convenience wrapper for error handling without try/catch

    example

    const [ err, items ] = await to(fetchJSON('/api/items')) if (err) console.error('Something happened')

    Type parameters

    • T

    Parameters

    • promise: PromiseLike<T> | T

    Returns Promise<[undefined, T] | [Error, undefined]>

Generated using TypeDoc