en.javascript.info/6-async/02-promise-basics/02-delay-promise/task.md
Ilya Kantor 455d300d8d renames
2017-05-25 11:56:32 +03:00

366 B

Delay with a promise

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) {
  // your code
}

delay(3000).then(() => alert('runs after 3 seconds'));