Skip to content

Instantly share code, notes, and snippets.

@wmakeev
Created March 13, 2022 12:56
Show Gist options
  • Save wmakeev/8b08460d78450e7a5eb6e3fdfe9361ce to your computer and use it in GitHub Desktop.
Save wmakeev/8b08460d78450e7a5eb6e3fdfe9361ce to your computer and use it in GitHub Desktop.
[resolve] #promise #tools #helpers
const resolve = async <T>(promise: Promise<T>) => {
try {
const result = await promise
return [result, null] as const
} catch (err) {
if (err instanceof Error) {
return [null, err] as const
} else {
throw err
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment