forked from wesbos/es6.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmultiple-promises.html
42 lines (37 loc) · 1 KB
/
multiple-promises.html
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
33
34
35
36
37
38
39
40
41
42
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Chaining Promises</title>
</head>
<body>
<script>
// const weather = new Promise((resolve) => {
// setTimeout(() => {
// resolve({ temp: 29, conditions: 'Sunny with Clouds'});
// }, 2000);
// });
// const tweets = new Promise((resolve) => {
// setTimeout(() => {
// resolve(['I like cake', 'BBQ is good too!']);
// }, 500);
// });
// Promise
// .all([weather, tweets])
// .then(responses => {
// const [weatherInfo, tweetInfo] = responses;
// console.log(weatherInfo, tweetInfo)
// });
const postsPromise = fetch('https://wesbos.com/wp-json/wp/v2/posts');
const streetCarsPromise = fetch('http://data.ratp.fr/api/datasets/1.0/search/?q=paris');
Promise
.all([postsPromise, streetCarsPromise])
.then(responses => {
return Promise.all(responses.map(res => res.json()))
})
.then(responses => {
console.log(responses);
});
</script>
</body>
</html>