Last active
October 19, 2020 08:07
-
-
Save istudyatuni/d134257b4fe505aa1ba3d9afedc3d8b1 to your computer and use it in GitHub Desktop.
Delay in TypeScript
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(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