2023-10-05 12:20:00 +02:00
|
|
|
/*
|
|
|
|
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:
|
|
|
|
*/
|
|
|
|
|
2024-02-23 11:17:02 +01:00
|
|
|
function delay (ms) {
|
|
|
|
return new Promise(resolve => {
|
|
|
|
setTimeout(resolve, ms);
|
|
|
|
});
|
2023-10-05 12:20:00 +02:00
|
|
|
}
|
|
|
|
|
2024-02-23 11:17:02 +01:00
|
|
|
delay(1000).then(() => console.log('Hello world!'));
|