Last active
July 26, 2023 13:08
-
-
Save TorbjornHoltmon/52487ac79d85fc984fffdb25a581caf4 to your computer and use it in GitHub Desktop.
Async callback
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
export async function CallBackTest<CallBackReturnValue>(callback: (asdasd: number) => Promise<CallBackReturnValue>) { | |
const result = await callback(123); | |
return { ...result, done: "YES!" }; | |
} | |
const callbackFunction = async (theNumber) => { | |
const anv = theNumber; | |
return returnWait(1000, { Hello: "worlaaaaad" }); | |
}; | |
async function DoThing() { | |
const whatIsThis = await CallBackTest(callbackFunction); | |
console.log(whatIsThis); | |
} | |
async function returnWait<T>(timeToDelay: number, returnValue: T): Promise<T> { | |
return new Promise((resolve) => setTimeout(() => resolve(returnValue), timeToDelay)); | |
} | |
// Its here! | |
DoThing(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment