Options
All
  • Public
  • Public/Protected
  • All
Menu

Module vx-tools/asyncFormat

异步包装

Index

Functions

Functions

asyncFormat

  • asyncFormat<T, U>(promise: Promise<T>): Promise<[T, null] | [null, U]>
  • async 异步包装

    summary

    将 aysnce await 错误作为返回值的处理方式

    example

    asynce load(){

     const [ res, err ] = await asyncFormat( api(...) )
    
     if(res === null){
       console.log(err)
       return
     }
    

    }

    Type parameters

    • T

    • U = any

    Parameters

    • promise: Promise<T>

      被包装promise

    Returns Promise<[T, null] | [null, U]>

    包装后的promise

Generated using TypeDoc