Created
August 12, 2020 17:39
-
-
Save LucasFsc/06d5c004afeefed618095965599b1936 to your computer and use it in GitHub Desktop.
Promise async try catch util
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
export default async ({ | |
promise, | |
onResponse = () => {}, | |
onLoad = () => {}, | |
onError = () => {}, | |
onComplete = () => {} | |
}) => { | |
onLoad(true) | |
try { | |
onResponse(await promise) | |
} catch (error) { | |
onError(error) | |
} finally { | |
onLoad(false) | |
onComplete() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment