Skip to content

Instantly share code, notes, and snippets.

@TorbjornHoltmon
Last active July 26, 2023 13:08
Show Gist options
  • Save TorbjornHoltmon/52487ac79d85fc984fffdb25a581caf4 to your computer and use it in GitHub Desktop.
Save TorbjornHoltmon/52487ac79d85fc984fffdb25a581caf4 to your computer and use it in GitHub Desktop.
Async callback
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