refactoring, modules
This commit is contained in:
parent
b8f6d96990
commit
a16814aaf1
112 changed files with 484 additions and 1825 deletions
|
@ -0,0 +1,9 @@
|
|||
```js run
|
||||
function delay(ms) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
delay(3000).then(() => alert('runs after 3 seconds'));
|
||||
```
|
||||
|
||||
Please note that in this task `resolve` is called without arguments. We don't return any value from `delay`, just ensure the delay.
|
14
1-js/09-async/02-promise-basics/02-delay-promise/task.md
Normal file
14
1-js/09-async/02-promise-basics/02-delay-promise/task.md
Normal file
|
@ -0,0 +1,14 @@
|
|||
|
||||
# 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:
|
||||
|
||||
```js
|
||||
function delay(ms) {
|
||||
// your code
|
||||
}
|
||||
|
||||
delay(3000).then(() => alert('runs after 3 seconds'));
|
||||
```
|
Loading…
Add table
Add a link
Reference in a new issue