Created
April 22, 2022 10:15
-
-
Save EvanBurbidge/09c6fca884e73124a2427b8885373036 to your computer and use it in GitHub Desktop.
Await wrapper example
This file contains 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
import { awaitWrap } from 'await-wrapper'; | |
const fakePromise = () => new Promise(resolve => setTimeout(resolve("hi")), 500); | |
const fakePromiseReject = () => new Promise((__, reject) => setTimeout(reject("no")), 500); | |
const fakePromiseHandler = async () => { | |
const { error, data } = await awaitWrap(fakePromise()); // { error: null, data: "hi" }; | |
error ? console.error(error) : console.log(data); | |
} | |
const fakePromiseRejectHandler = async () => { | |
const { error, data } = await awaitWrap(fakePromiseReject()); // { error: "no", data: null }; | |
error ? console.error(error) : console.log(data); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment