Skip to content

Instantly share code, notes, and snippets.

@phpsmarter
Created March 14, 2018 04:36
Show Gist options
  • Save phpsmarter/4065629196d4491cfcfe21e0b2c57bc7 to your computer and use it in GitHub Desktop.
Save phpsmarter/4065629196d4491cfcfe21e0b2c57bc7 to your computer and use it in GitHub Desktop.
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