This commit is contained in:
xfarrow
2023-10-11 12:37:20 +02:00
parent 0fbe12b5d4
commit 711e6d210a
12 changed files with 165 additions and 147 deletions

12
tutorials/delay.js Normal file
View File

@ -0,0 +1,12 @@
/*
The built-in function setTimeout uses callbacks. Create a promise-based alternative.
The function delay(ms) should return a promise. That promise should resolve after ms milliseconds, so that we can add .then to it, like this:
*/
function delay(ms){
return new Promise(resolve => {
setTimeout(resolve, ms);
});
}
delay(1000).then(() => console.log("Hello world!"));