Created
October 18, 2021 22:36
-
-
Save adilanchian/d988cab773c436b132ea719d55901baf to your computer and use it in GitHub Desktop.
Async Stuff
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
const asyncMethod = async () => { | |
console.log('Running asyncMethod...'); | |
const promise = new Promise((resolve, reject) => { | |
setTimeout(() => { | |
console.log('Waited 2 seconds!'); | |
resolve({ data: 'SomeData' }); | |
}, 2000); | |
}); | |
return await promise; | |
}; | |
const nonAsyncMethod = () => { | |
console.log('Running nonAsyncMethod...'); | |
return asyncMethod(); | |
}; | |
const main = async () => { | |
console.log('Running main...'); | |
const response = await nonAsyncMethod(); | |
console.log('Response:', response); | |
}; | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment