forked from TrainingByPackt/Professional-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExercise62.js
More file actions
32 lines (28 loc) · 720 Bytes
/
Exercise62.js
File metadata and controls
32 lines (28 loc) · 720 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const myPromise = new Promise((resolve) => {
resolve(12);
}).then((value) => {
console.log(value);
});
const myPromiseValue = Promise.resolve(12);
const myRejectedPromise = Promise.reject(new Error('rejected'));
myRejectedPromise.catch((error) => {
console.log(error);
});
function wait(seconds) {
return new Promise((resolve) => {
setTimeout(() => {
resolve(seconds);
}, seconds * 1000);
})
}
function waitCallback(seconds, callback) {
setTimeout(callback, seconds * 1000);
}
wait(2).then((seconds) => {
console.log('i waited ' + seconds + ' seconds');
});
wait(2)
.then(() => wait(2))
.then(() => {
console.log('i waited 4 seconds');
});