Created
March 14, 2018 04:36
-
-
Save phpsmarter/4065629196d4491cfcfe21e0b2c57bc7 to your computer and use it in GitHub Desktop.
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
function delay(milliseconds: number, count: number): Promise<number> { | |
return new Promise<number>(resolve => { | |
setTimeout(() => { | |
resolve(count); | |
}, milliseconds); | |
}); | |
} | |
// async function always returns a Promise | |
async function dramaticWelcome(): Promise<void> { | |
console.log("Hello"); | |
for (let i = 0; i < 5; i++) { | |
// await is converting Promise<number> into number | |
const count:number = await delay(500, i); | |
console.log(count); | |
} | |
console.log("World!"); | |
} | |
dramaticWelcome(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment