Skip to content

Instantly share code, notes, and snippets.

@istudyatuni
Last active October 19, 2020 08:07
Show Gist options
  • Save istudyatuni/d134257b4fe505aa1ba3d9afedc3d8b1 to your computer and use it in GitHub Desktop.
Save istudyatuni/d134257b4fe505aa1ba3d9afedc3d8b1 to your computer and use it in GitHub Desktop.
Delay in TypeScript
function delay(ms: number) {
return new Promise( resolve => setTimeout(resolve, ms) );
}
// call inside async function
await delay(300);
// not in async function
(async () => {
await delay(1000);
})();
// or
setTimeout(function(){ some_function() }, 1000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment