Skip to content

Instantly share code, notes, and snippets.

@yowchun93
Last active April 22, 2020 00:14
Show Gist options
  • Save yowchun93/4defb4b47a97bd31bc3d2e1f58cea227 to your computer and use it in GitHub Desktop.
Save yowchun93/4defb4b47a97bd31bc3d2e1f58cea227 to your computer and use it in GitHub Desktop.
Async Await in Typescript
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