Created
March 13, 2022 12:56
-
-
Save wmakeev/8b08460d78450e7a5eb6e3fdfe9361ce to your computer and use it in GitHub Desktop.
[resolve] #promise #tools #helpers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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