You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

promise.ts 295 B

1234567891011121314
  1. /**
  2. * @param { Promise } promise
  3. * @return { Promise }
  4. */
  5. export async function to<T, U = any>(promise: Promise<T>): Promise<[T, null] | [null, U]> {
  6. try {
  7. const data = await promise;
  8. return [data, null];
  9. } catch (error) {
  10. return [null, error as U];
  11. }
  12. }
  13. export default to;