Created
April 27, 2022 08:37
-
-
Save EvanBurbidge/ae874b28c4ea1a6af685268372c791f3 to your computer and use it in GitHub Desktop.
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 resolveCallback = response => { | |
// do something with response | |
} | |
const rejectCallback = error => { | |
// do something with error | |
} | |
const fakePromiseHandler = async () => { | |
const { error, data } = await awaitWrap(fakePromise(), { resolveCallback, rejectCallback }); // { error: null, data: "hi" }; | |
error ? console.error(error) : console.log(data); | |
} | |
const fakePromiseRejectHandler = async () => { | |
const { error, data } = await awaitWrap(fakePromiseReject(), { resolveCallback, rejectCallback }); // { 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