Last active
April 22, 2020 00:14
-
-
Save yowchun93/4defb4b47a97bd31bc3d2e1f58cea227 to your computer and use it in GitHub Desktop.
Async Await in Typescript
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
function delay(milliseconds: number, count: number): Promise<number> { | |
return new Promise<number>(resolve => { | |
setTimeout(() => { | |
resolve(count); | |
}, milliseconds ) | |
}) | |
} | |
async function dramaticWelcome(): Promise<void> { | |
for (let i = 0; i < 5; i++) { | |
// await is converting Promise<number> into number | |
const count:number = await delay(500, i); | |
console.log(count); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment